【发布时间】:2014-03-01 21:44:45
【问题描述】:
根据这里的一些帖子,我使用 Html.BeginFrom 而不是 Ajax.BeginForm,但在提交时我取得了控制权并返回带有部分视图的结果:
$('#SearchForm').on('submit', function (evt) {
evt.preventDefault();
$.post('/Search/Index', $(this).serialize(), function (response) {
$('#searchResults').html(response); // assuming response is HTML
});
});
这是我调用的操作:
[HttpPost]
public ActionResult Index(SearchModel searchModel)
{
if (ModelState.IsValid)
{
searchModel = CustomBehaviour.GetResults(searchModel);
return PartialView("SearchResults", searchModel);
}
return View(searchModel);
}
调试时调用了action,调用了js,也没有结果,请问是什么问题?
这里是视图:
@using (Html.BeginForm("Index", "Search", FormMethod.Post, new { role = "form", @class = "form-horizontal", id="SearchForm" }))
{
@Html.AntiForgeryToken();
@Html.EditorFor(m => m.Requirement)
@Html.EditorFor(m => m.Location)
<button type="submit" class="btn btn-default">@Base.Search</button>
}
<div id="#searchResults">
</div>
【问题讨论】:
-
是
ModelState.IsValid吗?
标签: jquery asp.net ajax asp.net-mvc asp.net-mvc-5