我有以下代码发布到我的搜索Json。问题是url重定向到json搜索并显示原始json数据。我想返回到partialView中的一个表。对如何实现这一点有什么想法吗?
<div>
@using (Html.BeginForm("Search", "Home", Formmethod.Get, new {id="search-form"})){
...
<button id="search-btn">Search</button>
}
</div>
<div>
<table id="search-results">...</table>
</div>我的家用控制器工作正常,但为了确保画面清晰...
public JsonResult Search(/*variables*/)
{
...
return Json(response, JsonRequestBehavior.AllowGet);
}然后我被重定向到“Search/(我的所有变量)”
发布于 2013-10-24 05:55:49
您的响应数据应该放入模型中,将模型传递给局部视图,并从控制器返回局部视图。
public PartialViewResult Search(/*variables*/)
{
...
YourModel model = new YourModel();
// Populate model
return PartialView("_YourPartialView", model);
}如果只想刷新局部视图,那么可以通过ajax调用控制器操作,并在ajax回调中调用$('#yourDivContainingThePartialView').html(response):
$.ajax({
url: urlToYourControllerAction,
method: 'get', // or 'post', depending on whether your controller action has side effects
success: function (response) {
$('#yourDivContainingThePartialView').html(response);
}
// other ajax options here if you need them
});https://stackoverflow.com/questions/19552986
复制相似问题