【发布时间】:2014-10-10 04:26:37
【问题描述】:
主视图包含@Ajax.ActionLink 链接,这些链接使用部分视图更新 div 目标。一切正常。
@Ajax.ActionLink("Update", "MemberInfo", new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "divCurrentView", InsertionMode = InsertionMode.Replace })
<div id="divCurrentView"></div>
问题是:当显示局部视图并单击当前时,我会更新数据并返回到重新加载数据的相同局部视图。还重新加载下拉列表..etc`
调用局部视图:
public PartialViewResult MemberInfo(){
.......
ViewBag.Members= new SelectList(_db.Members, "Id", "Text");
return PartialView("_MemberInfo",model);
}
[HttpPost]
public PartialViewResult MemberInfo(InformationVM model){
....... update data
//if I dont include the ViewBag again it will fail on reload
ViewBag.Members= new SelectList(_db.Members, "Id", "Text");
return PartialView("_MemberInfo",model);
}
我可以只在部分视图内的屏幕上显示“数据已更新”消息,而不是返回相同的 PartialView。?
【问题讨论】:
-
我建议您使用更多代码改进您的问题。现在有很多猜测。
-
是的,你可以。例如,从您的方法返回 204 No Content Status 代码。当您的 AJAX 调用成功时,显示消息。或
return Content("Success!")并显示。 -
@DasKrümelmonster 当我尝试返回 Content("Success!") 时出现错误无法将类型“System.Web.Mvc.ContentResult”隐式转换为“System.Web.Mvc.PartialViewResult”
-
将返回类型改为
ActionResult。 -
@DasKrümelmonster 它可以显示消息,但它会替换部分视图。是否可以显示带有部分视图内容的消息?
标签: asp.net-mvc asp.net-mvc-4 partial-views