I’m using
@(Html.EditorFor(m => m.Risk))
to show all the editable values for my Risk object. When this is posted to my controller that takes a Risk, which looks like this:
[HttpPost]
public ActionResult Add(Risk formRisk, string programId)
the Risk is created (which is just magical), but all of the string values are null, even though the Enum values are populated correctly. I’m also effectively getting another value passed in by form field name matching with no problem.
Anyone have any clues as to where to start looking at this since so much of it is based on convention?
Turns out the model of my view wasn’t the same type as the type my method I was posting the form to took as a parameter. Apparently, and this is deduced and may be wrong, but it appears that MVC 3 does some interesting reflection based magic when handling submitted forms. Let’s say I have a method like so:
If my form that I posted to this action has a field named “Title”, that value of that form element automatically gets set to any property on the parameter with the name “Title”. I didn’t know this happened, but it’s pretty cool and I’m leveraging it correctly now with EditorFor. =] Thanks to the 11 people who were interested.
This post earned me the tumbleweed badge because it was so uninteresting. =]