2011-12-10 4 views
0
나는 다음과 같은 모델을 가지고

에 손실 B 형태로. Id 값 (부분 뷰)은 모델의 Id 값 (0이 아닌 값)으로 올바르게 설정되어 있지만 페이지를 제출할 때 모델의 Id 값은 0입니다. Id 값은 구성 요소 또는 다른 위치에서 수정되지 않습니다 .모델 값은 다시 게시

페이지

...other parts of main page 

<%using (Html.BeginForm("ModifyHotel", "Hotel", 
        FormMethod.Post, new { enctype = "multipart/form-data"})) 
    {%> 
    <% Html.RenderPartial("~/Views/Shared/ModifyBaseItem.ascx", 
        new ModifyItemRequestBaseView() { ItemId = Model.Item.Id });%> 
<%}%> 

...other parts of main page 

부분보기

...other parts of partial view 
<br/>  
    Add Photo: <%:Html.FileBoxFor(x => x.PhotoFile, null)%>    
    <br/>  
    Add Video: <%:Html.FileBoxFor(x => x.VideoFile, null)%>    
    <br/> 
<input type="submit" value="Submit changes" /> 
...other parts of partial view 

나는 포스트가 만들어 질 때 내부 모델의 가치를 유지하기 위해 무엇을 할 수 있는가?

감사합니다,

+0

도와 드리겠습니다. – Romias

답변

2

컨트롤러 :

public class HomeController : Controller 
{ 
    public ActionResult Index() 
    { 
     A model = new A() { InnerField = new B() { Id = 5 }}; 
     return View(model); 
    } 

    [HttpPost] 
    public ActionResult Index(B model) 
    { 
     //on postback the model should have the value 5 here 
     return View(); 
    } 
} 

보기 :

@model MvcApplication11.Models.A 

@using (Html.BeginForm()) 
{ 
    @Html.Partial("_IndexForm", Model.InnerField) 

    <input type="submit" /> 
} 

부분 :

@model MvcApplication11.Models.B 

@Html.EditorFor(m => m.Id) 
+0

해당 라인을 추가하면 다음과 같이 표시됩니다 : ** 상대 가상 경로 'EditorTemplates/1.aspx'는 여기에서 허용되지 않습니다. ** (나는 면도기 구문을 사용하지 않습니다 ... .) –

+1

페이지에 Html.HiddenFor (m => m.Id)를 추가하여 작동하므로 비슷한 논리를 가졌기 때문에 답을 표시 할 것입니다. –