如何通过操作结果从另一个局部视图更新局部视图 [英] How to update partial view from another partial view via action results
本文介绍了如何通过操作结果从另一个局部视图更新局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在主视图上有三个局部视图
I have three partial views on main view
在第一个局部视图中,我具有搜索功能,当用户单击搜索时,我想将结果刷新到第三个局部视图中.
on the first partial view I have search functionality and when user clicks on search I want to refresh results into 3rd partial view.
控制器:
public ActionResult Search()
{
virtualmodel vm = new virtualmodel();
return PartialView(svm);
}
[HttpPost]
public ActionResult Search(ViewModel svm)
{
// Query to retrive the result
// I am not sure what to return from here. Link to another action or just return back to same same partial
}
public ActionResult AnotherPartialPartial()
{
}
在主视图中
@{Html.RenderAction("Search", "Searchc");
}
该怎么做?我需要ajax吗?
How to do it? Do I need ajax?
推荐答案
使用Ajax,您可以调用控制器动作并将其响应返回给特定的div
.
Using ajax you can call a controller action and return it's response to a particular div
.
空div
:
<div class="row" id="div3">
</div>
Ajax在空的div
中显示html:
Ajax to display html in empty div
:
function performSearch(searchCriteria) {
//get information to pass to controller
var searchInformation = JSON.stringify(**your search information**);
$.ajax({
url: '@Url.Action("Search", "ControllerName")',//controller name and action
type: 'POST',
data: { 'svm': searchInformation } //information for search
})
.success(function (result) {
$('#div3').html(result); //write returned partial view to empty div
})
.error(function (xhr, status) {
alert(status);
})
}
这篇关于如何通过操作结果从另一个局部视图更新局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文