【发布时间】:2017-01-24 19:41:55
【问题描述】:
我正在使用以下模式https://github.com/filamentgroup/Ajax-Include-Pattern 通过 ajax 加载部分视图。
查看:
@using(Html.BeginUmbracoForm("PostContactInformation", "JoiningSurface", null, new Dictionary<string, object> { { "class", "joinform" } })) {
@Html.AntiForgeryToken()
<div data-append="@Url.Action("RenderJoiningContactInformation", "JoiningSurface", new { ContentId = CurrentPage.Id })"></div>
}
有动作:
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();
}
在这种情况下,我得到当前模型的空值。这只发生在我使用 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,但我不确定这是最好的方法。 感谢您的耐心等待
【问题讨论】:
标签: ajax asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 umbraco