Search code examples
asp.net-mvcmvvmlambdaeditorfor

Is it possible to use Lambda with model of List<ViewModel>?


When the model is of type List, how can we use the lambda with it?

@model List<ViewModels.MyModel>

This does not work for EditorFor

@Html.EditorFor(m=>m.FirstOrDefault().Value)

How can I bind the model with the EditorFor?


Solution

  • You have iterate on it and do indexing as it is collection:

    @for(int i =0; i <Model.Count; i ++)
    {
        @Html.EditorFor(m=> Model[i].Value)
    }