The name of your AsmData[] parameter is answer, so you should name the various items:
answer[0].item ....etc
NOT
AsmData[0].Item....etc.
AsmData is the name of the type...parameters not types must match the names.
As an altermative you can change the name of the parameter to AsmData...however sinceit is the name of the type you might have problems with the compiler...try it anyway
Another possibility is using an unique ViewModel instead of three parameters. In this case the properties of the ViewModel instead of its name must match the names of the input fileds.
I advice To ALWAYS use a viewmodel for post action methods, instead of parameters...depndency from the ViewModel properties is acceptable...dependency on the e name of parameters....can caus eerrors if someone changes the parameter names
The name of your AsmData[] parameter is answer, so you should name the various items:
answer[0].item ....etc
NOT
AsmData[0].Item....etc.
Ok, I get the concept of what you are are saying, but how do I do that? Isn't that controled by the view? Here is the code the I am currently using to iterate through the questions:
It is simpler to change the name of the parameter, owever it match the name of the type...so this might create problems. Do the following:
Change the name of the AsmData property in the original model (the one you use to iterate in the view)...the important is that it is different from the name of any type.
Give to the parameter the same name as to the previous point
francesco ab...
All-Star
20912 Points
3279 Posts
Re: Model Binding to Custom Editor Template
May 07, 2012 09:30 AM|LINK
I found the error!
The name of your AsmData[] parameter is answer, so you should name the various items:
answer[0].item ....etc
NOT
AsmData[0].Item....etc.
AsmData is the name of the type...parameters not types must match the names.
As an altermative you can change the name of the parameter to AsmData...however sinceit is the name of the type you might have problems with the compiler...try it anyway
Another possibility is using an unique ViewModel instead of three parameters. In this case the properties of the ViewModel instead of its name must match the names of the input fileds.
I advice To ALWAYS use a viewmodel for post action methods, instead of parameters...depndency from the ViewModel properties is acceptable...dependency on the e name of parameters....can caus eerrors if someone changes the parameter names
Mvc Controls Toolkit | Data Moving Plug-in Videos
asteranup
All-Star
30184 Points
4906 Posts
Re: Model Binding to Custom Editor Template
May 07, 2012 10:26 AM|LINK
Hi,
I think you can use dictionary for this purpose-
http://growingtech.blogspot.in/2012/03/binding-posting-to-dictionary-in-mvc-3.html
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
ehcarleton
Member
33 Points
46 Posts
Re: Model Binding to Custom Editor Template
May 07, 2012 12:38 PM|LINK
@using(Html.BeginForm("Save", "MDSQuestion")) { <input type="submit" value="Save" /> @Html.HiddenFor(x => x.MdsId) @Html.HiddenFor(x => x.SectionId) for (var i = 0; i < Model.AsmtData.Count(); i++ ) { @Html.EditorFor(m => m.AsmtData[i]); } <input type="submit" value="Save" /> }francesco ab...
All-Star
20912 Points
3279 Posts
Re: Model Binding to Custom Editor Template
May 07, 2012 12:49 PM|LINK
It is simpler to change the name of the parameter, owever it match the name of the type...so this might create problems. Do the following:
This should fix
Mvc Controls Toolkit | Data Moving Plug-in Videos
ehcarleton
Member
33 Points
46 Posts
Re: Model Binding to Custom Editor Template
May 07, 2012 01:37 PM|LINK
Thank you! That got it! I knew it was something simple, just a matter of tracking it down!