我有一个代表搜索字段的@Html.EditorFor
。我试图在控制器中进行搜索,当字段中的文本被更改时。 我无法弄清楚如何每次在输入中更改文本时进行回发,而不是在单击提交按钮时进行回发。如何去mtc中@ Html.EditorFor的更改回发?
型号:
public class MainWindow
{
[Key]
public int MainWindowId { get; set; }
public string SearchedString { get; set; }
}
查看:
@using (Html.BeginForm())
{
<div>
<label>search:</label>
@Html.EditorFor(model => model.SearchedString, new htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SearchedString, "", new { @class = "text-danger" })
<input type="submit" value="search" class="btn btn-default" />
</div>
}
控制器:
[HttpPost]
public ActionResult Index([Bind(Include = "MainWindowId,SearchedString")] MainWindow mw)
{
ManageProduct mp = new ManageProduct();
if (ModelState.IsValid)
{
//search code
return View("Index",mw);
}
return View(mw);
}
你想要什么,自动完成这样的功能? –
你应该使用javascript的ajax请求 –