0

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?

4
  • Are you talking about @model Model_Name at the top of the .cshtml page? Commented Oct 31, 2016 at 22:49
  • 1
    where did you get this QuantidadeParcelas from? Commented Oct 31, 2016 at 23:44
  • @pjobs, QuantidadeParcelas comes from the PlanoPagamentoViewModel (the viewmodel of the PartialView) Commented Nov 1, 2016 at 9:47
  • @VadzimSavenok More or less, I think I need to change the name of the element to get the binding of the PartialView , working when I POST the MainView Commented Nov 1, 2016 at 10:19

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I understood your idea, thanks for the help man. As asp.net MVC work with convention name, my partial view was generating the name of the fields that was not being recognized by the main view model, so I had to put the full path name in order to get it working!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.