2016-09-16 69 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

不客氣。樂意效勞 :) –