0
我使用以下模式https://github.com/filamentgroup/Ajax-Include-Pattern 通过ajax加载部分视图。模型在ajax加载的部分视图中回发时为null
检视:
随着操作:
public ActionResult RenderContactInformation(int ContentId)
{
var viewModel = ContactViewModel();
viewModel.Content = Umbraco.TypedContent(ContentId);
return PartialView("RenderContactInformation", viewModel);
}
载荷局部视图完美。
//无需添加局部视图我想
行动后正常工作,以及:
public ActionResult PostContactInformation(ContactViewModel model)
{
//code here
return RedirectToUmbracoPage(pageid);
}
的问题是,我需要添加模型误差CurrentUmbracoPage如果在后期存在...
例如:
public ActionResult PostContactInformation(ContactViewModel model)
{
ModelState.AddModelError(string.Empty, "Error occurred");
return CurrentUmbracoPage();
}
在这种情况下,我得到NUL l当前模型的值。而这只发生在我使用ajax的时候。
如果我同步加载操作这样的:
@using(Html.BeginUmbracoForm("PostJoiningContactInformation", "JoiningSurface", null, new Dictionary<string, object> { { "class", "joinform" } })) {
@Html.AntiForgeryToken()
@Html.Action("RenderContactInformation", "JoiningSurface", new { ContentId = CurrentPage.Id })
}
一切工作像它应该。
但我需要使用ajax。在这种情况下是否有正确的方式来传递回传值?我知道我可以使用TempData,但我不确定这是最好的方法。 感谢您的耐心配合
感谢您的回应,Marcin! – progproger
不客气。乐意效劳 :) –