MVC: pass IEnumerable inside ViewModel into EditorForModel() template?

402 views Asked by At

this is my very first question here, so Id greatly appreciate if I could get some helps. Well...I have the code below where i send IEnumerable into View, the EditorForModel render the whole list to be edit just fine.

View:

@model IEnumerable<App.Models.Requirements>
... 
<form>@Html.EditorForModel()</form>   //inside the template, I use @model App.Models.Requirements
...

The issue is that now I want to pass more stuff into the View, so I create ViewModel kinda like...

public class PersonReqModel
{
    public People Person { get; set; }
    public IEnumerable<Requirements> Requirements{ get; set; }
}

And pass the ViewModel into the View like...

@model App.ViewModels.PersonReqModel
... 
<form>@Html.EditorForModel()</form>
...

Now the EditorForModel render nothing, as expected, I tried a few things but I can't seem to past the IEnumerable Requirements into the Template.

Does anyone have a solution to this? Thanks!

0

There are 0 answers