Lets say I have a a form that can have new text inputs created in JavaScript at runtime. And I want to bind the values to a NameValueCollection (or a Dictionary). Does ASP.NET MVC3 natively allow this?
In other words, how do I get this to work?
Assuming this is the HTML form...
<!-- if someone posted this form -->
<form action="MyExample">
<input type="hidden" name="id" value="123" />
<input type="text" name="things.abc" value="blah" />
<input type="text" name="things.def" value="happy" />
<input type="text" name="things.ghi" value="pelicans" />
<input type="submit" />
</form>
... and this is is the "Action" in the Controller ...
public ActionResult MyExample(int id, NameValueCollection things)
{
// At this point, `things["abc"]` should equal `"blah"`
return Content(string.Format("Things has {0} values.", things.Count));
}
Do I need to make my own custom model binder? Or am I just naming the input boxes incorrectly?
Request.Formvalues..Request.Formwould be easy... not really good for TDD :) - I'm architecting a project, and one of the requirements I've set out is that no MVC developers can access "Session", "Request", "Cookies", etc (directly).