我正在使用asp.net mvc5并尝试在我的表格上方添加一个文本框来搜索表格中的项目。在我看来,我有
@using (Html.BeginForm())
{
<p>
Find by Start/End Point @Html.TextBox("SearchString")
<input type="submit" value="Search" />
</p>
}
然后在我的控制器中
public ActionResult Index(string sortOrder, string searchString)
{
var lift = from l in db.Lifts select l;
if (!String.IsNullOrEmpty(searchString))
{
lift = lift.Where(l => l.StartPoint.Contains(searchString)
|| l.EndPoint.Contains(searchString));
}
return View(lifts.ToList());
}
}
但是每次都会返回相同的表格。这可能是愚蠢的我做错了但我无法看到。
答案 0 :(得分:0)
尝试使用:
@using (Html.BeginForm("Index","ControllerName",new { sortOrder = "Desc/Asc" },FormMethod.Post))
{
<p>
Find by Start/End Point @Html.TextBox("SearchString")
<input type="submit" value="Search" /></p>
}
行动代码: -
public ActionResult Index(string sortOrder, string SearchString)
{
var lift = from l in db.Lifts select l;
if (!String.IsNullOrEmpty(SearchString))
{
lift = lift.Where(l => l.StartPoint.Contains(SearchString)
|| l.EndPoint.Contains(SearchString));
}
return View(lifts.ToList());
}
}