2016-09-16 70 views
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,但我不确定这是最好的方法。 感谢您的耐心配合

回答

1

问题是,当您尝试通过ajax调用来访问Umbraco上下文时,无法访问。这些电话有点不同。

检查我的回答在这个线程:Umbraco route definition-ajax form,我建议去与WebAPI和UmbracoApiControllers能够在Ajax调用期间访问这些值。

+0

感谢您的回应,Marcin! – progproger

+0

不客气。乐意效劳 :) –