根据这里的一些帖子,我使用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);
}
调试时调用动作并调用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>
答案 0 :(得分:1)
问题是你的div id:
<div id="#searchResults">
</div>
需要:
<div id="searchResults">
</div>