我的索引页面包含以下代码:
<div class="editor-field">
@Html.CheckBoxFor(model => model.IncludeArchive)
@Html.ValidationMessageFor(model => model.IncludeArchive)
</div>
我的模型是:
public class SearchModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string TestNumber { get; set; }
public bool IncludeArchive { get; set; }
}
[Authorize]
public ActionResult Index(SearchModel search)
{
var test= db.Test.AsQueryable();
if (Request.QueryString.Count > 0) {
if (!search.IncludeArchive) test = test.Where(x => x.Status == "Active");
} else {
test= test.Where(x => x.Status == "Active");
}
ViewBag.testList = test.ToList();
当浏览到页面然后选择 IncludeArchive 复选框以将其启用为 true 时,查询字符串变为
http://localhost:64005/test/?FirstName=&LastName=&TestNumber=&IncludeArchive=true&IncludeArchive=false
为什么它在查询字符串中包含两次变量 IncludeArchive?
谢谢