2016-10-31 2 views
0

MainView에 콤보 박스가 있으며이 콤보 박스에는 MainView에서 렌더링 할 PartialView를 반환하는 서버에 대한 AJAX 호출이 있습니다.Asp.Net 동적 바인딩 렌더링 된 부분 뷰

MAINVIEW 다음 VieModel 있습니다

public class CupomFiscalDetalhesViewModel 
{ 
    //Properties 
    public PlanoPagamentoViewModel PlanoPagamentoSelecionado { get; set; }  
} 

PartialView, 다음 뷰 모델이 있습니다을 :

인터페이스는이 경우에 내가 보여 줄게, 다른 두 ViewModels에 의해 구현 될 수

public class PlanoPagamentoViewModel 
{ 
    public int QuantidadeParcelas {get; set;} 
    public IPlanoPagamentosParcelas PlanoPagamentosParcelas { get; set; } 
} 
ViewModel은 다음을 구현합니다.

public class PlanoPagamentoCartaoViewModel : IPlanoPagamentosParcelas 
{ 
    public List<ParcelaViewModel> Parcelas { get; set; } 
} 

일단 사용자가 값을 콤보 박스, 동적으로 jQuery 아약스 부분 뷰 중 하나를 사용하여로드합니다.

나는 PartialView에 결합하기 위해 노력하고있어 방법의 예 :

모델이 나는 부분보기 속성의 중첩 된 속성에 바인딩 어떻게해야합니까 PlanoPagamentoViewModel

의 유형이

@for (int i = 0; i < Model.QuantidadeParcelas; i++) 
{      
    @Html.EditorFor(model => model.PlanoPagamentosParcelas.Parcelas[i].DataVencimento, new { htmlAttributes = new { @class = "form-control col-md-offset-4" } }) 
} 

POST 동작에서 내 CupomFiscalDetalhesViewModel?

+0

.cshtml 페이지 상단에'@model Model_Name'에 대해 이야기하고 있습니까? –

+1

어디에서이 QuantidadeParcelas를 얻었습니까? – pjobs

+0

@pjobs, QuantidadeParcelas는 PlanoPagamentoViewModel (PartialView의 뷰 모델)에서 제공됩니다. – Maturano

답변

1

내가 수집 한 것부터, 클래스가 위치한 곳에 네임 스페이스를 포함시켜야한다고 생각합니다. @using namespace_name_where_PlanoPagamentoViewModel_class_is_located@model model_name이 있습니다.

+0

도움의 손길에 감사드립니다. asp.net MVC가 대회 이름으로 작업 할 때, 내 부분보기는 기본보기 모델에서 인식되지 않는 필드의 이름을 생성하므로 전체 경로 이름을 입력해야 작업 할 수 있습니다. – Maturano