我看了一堆其他報告這個,但我的行爲有點不同。我爲我的子操作返回PartialViewResults,因此這不是遞歸的來源。這是我所擁有的一個愚蠢的版本。MVC 3 StackOverflowException瓦特/ @ Html.Action()
// The Controller
[ChildActionOnly]
public ActionResult _EditBillingInfo()
{
// Generate model
return PartialView(model);
}
[HttpPost]
public ActionResult _EditBillingInfo(EditBillingInfoViewModel model)
{
// Update billing informatoin
var profileModel = new EditProfileViewModel()
{
PartialToLoad = "_EditBillingInfo"
};
return View("EditProfile", profileModel);
}
[ChildActionOnly]
public ActionResult _EditUserInfo()
{
// Generate model
return PartialView(model);
}
[HttpPost]
public ActionResult _EditUserInfo(EditUserInfoViewModel model)
{
// Update user informatoin
var profileModel = new EditProfileViewModel()
{
PartialToLoad = "_EditUserInfo"
};
return View("EditProfile", profileModel);
}
public ActionResult EditProfile(EditProfileViewModel model)
{
if (String.IsNullOrEmpty(model.PartialToLoad))
{
model.PartialToLoad = "_EditUserInfo";
}
return View(model);
}
// EditProfile View
@model UPLEX.Web.ViewModels.EditProfileViewModel
@{
ViewBag.Title = "Edit Profile";
Layout = "~/Views/Shared/_LoggedInLayout.cshtml";
}
<div>
<h2>Edit Profile</h2>
<ul>
<li class="up one"><span>@Ajax.ActionLink("Account Information", "_EditUserInfo",
new AjaxOptions { UpdateTargetId = "EditProfileDiv", LoadingElementId = "LoadingImage" })</span></li>
<li class="up two"><span>@Ajax.ActionLink("Billing Information", "_EditBillingInfo",
new AjaxOptions { UpdateTargetId = "EditProfileDiv", LoadingElementId = "LoadingImage" })</span></li>
</ul>
<img alt="Loading Image" id="LoadingImage" style="display: none;" src="../../Content/Images/Misc/ajax-loader.gif" />
<div id="EditProfileDiv">
@Html.Action(Model.PartialToLoad)
</div>
</div>
部分視圖都是用於更新用戶信息或帳單信息的表單。
我調試通過這個,發現發生了什麼,但無法弄清楚爲什麼。當用戶瀏覽到EditProfile時,它會加載_EditUserInfo部分,並且表單在那裏進行編輯。當您更改某些信息並提交表單時,它會掛起,並在調用@Html.Action()
時在EditProfile視圖中出現StackOverflowException。在EditProfile初始訪問時會發生什麼,@Html.Action
調用_EditUserInfo的HttpGet版本。您對用戶信息進行了一些更改,然後單擊「提交」。信息更新後,EditProfile視圖會再次返回,但此時@Html.Action
將調用_EditUserInfo的HttpPost版本,該版本再次更新用戶信息,再次返回EditProfile視圖,並調用_EditUserInfo的HttpPost版本。正在發生。爲什麼在提交表單後它會調用post版本,而不是像EditProfile的初始訪問那樣獲取版本?
感謝您的幫助!