다음 패턴을 사용합니다. https://github.com/filamentgroup/Ajax-Include-Pattern 아약스를 통해 부분 뷰를로드합니다.ajax가로드 된 부분 뷰에서 모델이 포스트 백에 null입니다.
보기 : 액션으로
@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();
}
이 경우 내가 NUL을 얻을 현재 모델에 대한 l 값. 그리고 이것은 아약스를 사용할 때만 발생합니다.
내가 그런 기적 조치를로드하는 경우가해야처럼
@using(Html.BeginUmbracoForm("PostJoiningContactInformation", "JoiningSurface", null, new Dictionary<string, object> { { "class", "joinform" } })) {
@Html.AntiForgeryToken()
@Html.Action("RenderContactInformation", "JoiningSurface", new { ContentId = CurrentPage.Id })
}
모든 작품.
하지만 아약스를 사용해야합니다. 이 경우 포스트 백에 값을 전달하는 올바른 방법이 있습니까? 나는 TempData를 사용할 수 있지만이 방법이 최선의 방법인지 확신 할 수 없다. 양해 해 주셔서 감사합니다.
응답 해 주셔서 감사합니다. Marcin! – progproger
당신을 진심으로 환영합니다. 도와 줘서 다행 :) –