Dynamic name string editorfor ASP.NET MVC

79 Views Asked by At

Model:

public class abc
{
    public long? Id { get; set; }
    public long? p1 { get; set; }
    public long pa1 { get; set; }
    public long? bv1 { get; set; }
    public string ad1 { get; set; }
}

View:

List<object> value_model = new List<object>();

value_model.Add(new value_model{ namemodel= "ad1", display= "display addd"});
value_model.Add(new value_model{ namemodel= "pa1", display= "display pa1 "});`

@foreach (var item in collection)
{
    <label>item.display</label>
    @Html.EditorFor(m =>item.namemodel)
}

I want to pass the value of model name and will get back to EditorFor as I want. But I can't do it. Hope to work.

0

There are 0 best solutions below