2012-08-30 4 views
1

이 질문은 수 시간을 요구했지만 지금은 꽤 많은 시간을 낭비 했으므로 마침내 게시합니다. 그래서 요약하면 일부 복잡한 유형 특성 및 복합 유형 목록 특성을 갖는보기 모델이 있습니다.목록 속성이 컨트롤러의 게시물에 바인딩되지 않습니다.

public class ViewModel 
{ 
    public ViewModel() 
    { 
     Gains = new List<Gain>(); 

    } 
    [UIHint("Common")] 
    public AllRegRecordsLog commonRegisterFields { get; set; } 
    public Potential Potential { get; set; } 
    [UIHint("Gains")] 
    public List<Gain> Gains { get; set; } 

    public void CreateGains(int count = 1) 
    { 

     for (int i = 0; i < count; i++) 
     { 

      Gains.Add(new Gain()); 

     } 


    } 

} 

내가

@model Gains 
    table id="gainsTable" class="content-tables"style="width:98%"> 
    <tr id="defaultGainsRow"> 
      <td class="editor-label"> 
       @Html.LabelFor(model => model.VolumeGainLow) 
      </td> 
      <td class="editor-field"> 
       @Html.TextBoxFor(model => model.VolumeGainLow) 
       @Html.ValidationMessageFor(model => model.VolumeGainLow) 
      </td> 

      </tr> 

    <tr> 
    <td colspan="4"> 
     <input id="addGainsButton"type="button" class="t-button" Value="Add Potential Gains"/> 
    </td> 
    </tr> 
    </table> 

그러나 어떻게 든 나는 오류는 "얻을 내 특정보기 폴더 안에 편집기 템플릿을 배치 한

@Html.EditorFor(model => model.Gains) 

내가으로이 속성을 호출 지금 내보기 createOrEdit, 사전에 전달 된 모델 항목의 형식은 'System.Collections.Generic.List이지만 예상대로입니다.'

asp.Net MVC 4

올바른 방향으로 알려주십시오.

감사

빌랄

답변

0

목록을 가지고 또한

@model List<Gain> 
@foreach(var gain in Model) 
{ 
    table id="gainsTable" class="content-tables"style="width:98%"> 
    <tr id="defaultGainsRow"> 
      <td class="editor-label"> 
       @Html.LabelFor(gain=> gain.VolumeGainLow) 
      </td> 
      <td class="editor-field"> 
       @Html.TextBoxFor(gain=> gain.VolumeGainLow) 
       @Html.ValidationMessageFor(gain=> gain.VolumeGainLow) 
      </td> 

      </tr> 

    <tr> 
    <td colspan="4"> 
     <input id="addGainsButton"type="button" class="t-button" Value="Add Potential Gains"/> 
    </td> 
    </tr> 
    </table> 
} 

EDIT 내부의 루프 로직을 수행 할 editortemplate 수정 : 내 면도기가 100 %되지 않을 수 있습니다하지만 당신은 아이디어를 얻을

+0

감사를 사용 solvex. : ( – Bilal

0

유형 대신 속성에 대한 경계로보기를 선언하려는 것 같습니다. 이건 불가능 해. 템플리트가 작동하려면 웹 프로젝트에서 참조하는 유효한 유형으로 모델을 선언해야합니다.

Gains 속성의 유형은 List<Gain>. Since your 이익 view has a 이익 type declared, your UIHintAttribute`가 무효입니다. 지원들에 대한

+0

좋아, 이제 그것을 제거했지만보기에 아무것도 나타나지 않는다. – Bilal

관련 문제