主視圖包含@Ajax.ActionLink
用partialView更新div目標的鏈接。一切正常。MVC4部分視圖無返回
@Ajax.ActionLink("Update", "MemberInfo", new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "divCurrentView", InsertionMode = InsertionMode.Replace })
<div id="divCurrentView"></div>
的問題是:當顯示partialview和點擊我目前更新數據並返回到重新加載數據的相同局部視圖。同時會dropdownlists..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我可以只顯示局部視圖內的屏幕上顯示「數據被更新」的消息?
我建議你用更多的代碼來改善你的問題。現在很多猜測。 – Mrchief 2014-10-09 19:40:41
是的,你可以。例如,返回方法中沒有內容狀態代碼。當您的AJAX調用成功時,顯示消息。或'返回內容(「成功!」)並顯示。 – 2014-10-09 19:42:05
@DasKrümelmonster當我嘗試返回內容(「成功!」)我得到一個錯誤不能隱式地將類型'System.Web.Mvc.ContentResult'轉換爲'System.Web.Mvc.PartialViewResult – Ben 2014-10-09 19:44:25