I have a form that posts a bunch of hidden variables, some with the same name. Here's the post body:
OfferId=3802&DeliveryDate=11%2F02%2F2011&DeliveryTime=12%3A00&location=1&location=698
It posts it to an MVC action:
[HttpPost]
public ActionResult DeliveryOptions(DeliveryOptions model)
{
...
}
The DeliveryOptions model looks like this:
public class DeliveryOptions
{
public long? OfferId { get; set; }
[CustomValidation(typeof(CustomValidator), "IsDeliveryDateValid")]
public DateTime? DeliveryDate { get; set; }
public DateTime? DeliveryTime { get; set; }
[CustomValidation(typeof(CustomValidator), "IsLocationsValid")]
public OfferLocations Locations { get; set; }
}
Now, I would like to parse the posted location
variables into the OfferLocations object, which looks like this:
[ModelBinder(typeof(OfferLocationsModelBinder))]
public class OfferLocations
{
[Required]
public int[] LocationIds { get; set; }
}
The model binder currently looks like this:
public class OfferLocationsModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
throw new NotImplementedException();
}
}
The problem is, I cannot break on the NotImplementedException. The model binder does not execute. I've probably missed something obvious; any ideas?
Couldn't get this to work. Had to implement a workaround.
I'm now posting the location IDs as a CSV string, and they are being picked up by the custom model binder, so can be parsed into the array. Shame I couldn't do it the other way.