I would like to do complex validation on my form that contains a list of objects.
My form contains a list of, let's say, MyObjects. MyObject consists of a double amount and a MyDate which is just a wrapper around DateTime.
public class MyObject
{
public MyDate Date { get; set; } //MyDate is wrapper around DateTime
public double Price { get; set; }
}
The form...
<input type="text" name="myList[0].Date" value="05/11/2009" />
<input type="text" name="myList[0].Price" value="100,000,000" />
<input type="text" name="myList[1].Date" value="05/11/2009" />
<input type="text" name="myList[1].Price" value="2.23" />
Here is my Action
public ActionResult Index(IList<MyObject> myList)
{
//stuff
}
I want to allow the user to enter in 100,000,000 for a Price and for the custom model binder to strip the ',' so it can convert to a double. Likewise, I need to convert the 05/11/2009 to a MyDate object. I thought about creating a MyObjectModelBinder but dont know what to do from there.
ModelBinders.Binders[typeof(MyObject)] = new MyObjectModelBinder();
Any help appreciated.