2011-08-25 2 views
0

부분 뷰 내에서 ActionResult를 호출 할 때 상위 뷰를 반환하려고합니다. 부모보기를 알고 있다면 반환보기 ("Index");로 입력 할 수 있지만이 부분보기가 공유되므로 여러 부모보기가 될 수는 없습니다. 따라서 올바른 부모보기를 반환하는 방법은 무엇입니까? ActionResult에서?공유 부분 뷰 ActionResult 문제

이 너무 간단 보이지만 그것은 나를 난처한 상황에 빠진있다 ...

업데이트.

@model Website.Models.PostModel 

@using (Html.BeginForm("SubmitPost", "Home", FormMethod.Post)) 
{ 
@Html.TextAreaFor(m => m.Message, 2, 50, null) 
<br /><br /> 
<div class="ui-widget"> 
    Notes: @Html.TextBox("Notes", "", new { @class = "ui-autocomplete-input" }) 
</div> 
<br /> 
<p> 
    <input type="submit" value="Post" /> 
</p> 

}

답변

4

난 당신이 그렇다면, 당신은뿐만 아니라 당신의 routeValues을 지정할 수 있다면

[ChildActionOnly] 
public ActionResult Action() 
{ 
    var model = context.Data.Where(x => x); 

    return PartialView("PartialView", model); 
} 

전화를보기에 @{Html.RenderAction("Action");}를 사용하는 가정 : 여기 부분보기입니다. 보기에 당신은

@{Html.RenderAction("Action", new {viewName = "parentView"});} 

를 호출하고 컨트롤러 것 : 내 제출 버튼 HTML.BeginForm을 사용하고

[ChildActionOnly] 
public ActionResult Action(string viewName) 
{ 
    var model = context.Data.Where(x => x); 

    if (model == null) return View(viewName); 

    return PartialView("PartialView", model); 
} 
+0

. 부모의 모델을 부분 뷰에 전달해야합니까? – Allensb

+0

마지막으로 알아 냈습니다. 당신이 지적한 것처럼 부분 렌더링에 뷰 이름을 전달해야했습니다. 도와 주셔서 감사합니다! – Allensb