c# - MVC Form: Post Propertylist -



c# - MVC Form: Post Propertylist -

i have viewmodel has list property of type class x. when seek post property server, recived list null.

the info transmitted client looks this:

... xxx.[0].test:false xxx.[0].test1:true xxx.[1].test:false xxx.[1].test1:false ...

the viewmodels looks this:

class viewmodel { public viewmodel() { this.xxx = new list<testviewmodel>() } public list<testviewmodel> xxx { get; set; } } public testviewmodel { public bool test{ get; set; } public bool test1 { get; set; } }

the view generated edittemplate

form:

using (html.beginform(null, null, formmethod.post)) { @html.editorfor(m => m.viewmodel) }

editortemplates:

@model list<testviewmodel> @for (int = 0; < model.count; i++) { @html.checkboxfor(p => model[i].test) @html.checkboxfor(p => model[i].test1) }

the prooblem seems additional point...( xxx**.**[0] ) thanks

change editortemplate model object (not collection)

testviewmodel.cshtml

@model testviewmodel @html.checkboxfor(m => m.test) @html.checkboxfor(m => m.test1)

and main view to

@model viewmodel using (html.beginform(null, null, formmethod.post)) { @html.editorfor(m => m.xxx) .... }

the editorfor() method correctly name controls indexers, like

<input type="checkbox" name="xxx[0].test" .../> <input type="hidden" name="xxx[0].test" .../> .... <input type="checkbox" name="xxx[1].test" .../> <input type="hidden" name="xxx[1].test" .../>

c# asp.net-mvc model-view-controller subclass form-submit

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -