我的 Asp.Net MVC 4 在索引视图中有以下代码。
<form action="/Deal" method="GET">
<p>
@Html.ActionLink("Create New", "Create")
<input type="text" name="search"/>
<input type="submit" value="Search" />
</p>
</form>
以及 DealController 中的以下代码。但是,回发后的 html 搜索输入是空的。在输入框中显示键入的搜索字符串以便用户继续修改它的最佳方式是什么?
public ActionResult Index(string search)
{
var deals = Deals.Include(d => d.Address);
if (search != null)
deals =
deals.Where(d => d.Address.ApartmentNum.Contains(search)
|| d.Address.StreetAddress.Contains(search)
|| d.Address.City.Contains(search)
|| d.Address.State == search
|| d.Address.Zip == search);
return View(deals.ToList());
}