Maturano
Maturano

Reputation: 1023

Asp.Net MVC, binding dynamically rendered Partial View

I have a Combobox in the MainView and this Combobox has an AJAX call to the server that returns a PartialView to be renderized in the MainView.

The MainView has the following VieModel:

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

The PartialView, has the following ViewModel:

public class PlanoPagamentoViewModel 
{
    public int QuantidadeParcelas {get; set;}
    public IPlanoPagamentosParcelas PlanoPagamentosParcelas { get; set; }   
}

The interface can be implemented by two other ViewModels, in this case I'll show which ViewModel is implementing:

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

Once the user changes the value of the Combobox,I load dynamically using jQuery ajax one of the partial views.

An example of how I'm trying to bind in the PartialView:

@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" } })
}

Where Model is the type of PlanoPagamentoViewModel

How do I make the partial view properties bind to the nested property of my CupomFiscalDetalhesViewModel in the POST action?

Upvotes: 0

Views: 780

Answers (1)

Vadzim Savenok
Vadzim Savenok

Reputation: 960

From what I gather, I think you need to include the namespace where your class is located through @using namespace_name_where_PlanoPagamentoViewModel_class_is_located alongside with @model model_name.

Upvotes: 1

Related Questions