Nil*_*Nil 5 c# ajax asp.net-mvc partial-views asp.net-mvc-4
在第一个局部视图中我有搜索功能,当用户点击搜索时我想将结果刷新到第三个局部视图.
控制器:
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()
{
}
Run Code Online (Sandbox Code Playgroud)
在主要观点
@{Html.RenderAction("Search", "Searchc");
}
Run Code Online (Sandbox Code Playgroud)
怎么做?我需要ajax吗?
小智 0
因此,假设您有带有 PartialView 的视图,必须通过单击按钮进行更新:
<div class="target">
@{ Html.RenderAction("UpdatePoints");}
</div>
<input class="button" value="update" />
Run Code Online (Sandbox Code Playgroud)
有一些方法可以做到这一点。例如,您可以使用 jQuery:
<script type="text/javascript">
$(function(){
$('.button')click(function(){
$.post('@Url.Action("PostActionToUpdatePoints", "Home")').always(function(){
$('.traget').Load('/Home/UpdatePoints');
})
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
PostActionToUpdatePoints 是具有 [HttpPost] 属性的操作,用于更新点
如果您在操作 UpdatePoints() 中使用逻辑来更新点,则可能您忘记向其添加 [HttpPost] 属性:
[HttpPost]
public ActionResult UpdatePoints()
{
ViewBag.points = _Repository.Points;
return PartialView("UpdatePoints");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7572 次 |
| 最近记录: |