你應該有你的ActionResult
把它們作爲參數,像這樣(我假設bool
,如果他們int
,將其更改爲int
)。
public ActionResult Environments(bool House, bool Car, bool Work)
然後你就可以在你的LINQ語句中使用它們,這樣的:
int totalSmokers = repository.Results
.Where(x => x.House == House && x.Car == Car && x.Work == Work)
.Count();
即使清潔雖然,你可以創建一個模型(以及在您的視圖返回這個就像你在評論中問道, ),是這樣的:
public class SmokersModel
{
public bool House { get; set; }
public bool Car { get; set; }
public bool Work { get; set; }
public int TotalSmokers { get; set; }
}
然後就是收拾你的操作方法,你可以這樣做:
public ActionResult Environment(SmokersModel Model)
{
Model.TotalSmokers = repository.Results
.Where(x => x.House == Model.House && x.Car == Model.Car && x.Work == Model.Work)
.Count();
return View(Model);
}
然後改變你的看法的模式類型爲SmokersModel
:
@model SmokersModel
HttpContext.Request.params還允許您訪問查詢字符串 – 2013-05-07 15:00:54