c# - Bind EditorFor to Array of string -
c# - Bind EditorFor to Array of string -
after trying more sophisticated viewmodel no success came utilize viewmodel this:
public class carteexpressviewmodel { public string[] lesentrees; public string[] lesplats; public carteexpressviewmodel() { lesentrees = new string[]{ "", "", "", "", "", "" }; lesplats = new string[]{ "", "", "", "", "", "" }; } }
i pass viewmodel in create method of controller
public actionresult create() { carteexpressviewmodel carteexpressviewmodel = new carteexpressviewmodel(); homecoming view(carteexpressviewmodel); }
problem can see input value if utilize formcollection
parameter of post create method null if utilize viewmodel view line this:
@for (int = 0; < model.lesentrees.length; i++) { <div class="editor-label "> @html.labelfor(model => model.lesentrees[i], "entrĂ©e n°" + (i + 1).tostring(), new { @class = " express_input_label" }) </div> <div class="editor-field "> @html.editorfor(model => model.lesentrees[i], new { @class = " express-input" }) </div> }
i can't see what's wrong sure should.
you set variables fields, not properties. alter them to:
public string[] lesentrees { get; set; } public string[] lesplats { get; set; }
c# asp.net-mvc model-binding asp.net-mvc-viewmodel
Comments
Post a Comment