I tried your example, and my conclusion is that the DefaultModelBinder in ASP.NET MVC does not support this assignment of POST variables.
The obvious solution is not to use dashes in your names.
If this is not an option, you can implement your own connecting device for this particular model to handle the anomalous names that you send to your MVC controller. The following is an example of a custom mediation:
public class AModelDataBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { if (bindingContext.ModelType == typeof(AModel)) { var request = controllerContext.HttpContext.Request; string normal = request.Form.Get("normalproperty"); string abnormal = request.Form.Get("abnormal-property"); return new AModel { NormalProperty = normal, AbnormalProperty = abnormal }; } return base.BindModel(controllerContext, bindingContext); } }
Then you will need to register this custom binder in Global.asax :
ModelBinders.Binders.Add(typeof(AModel), new AModelDataBinder());
And finally, you can use a custom binder in your controller:
[HttpPost] public ActionResult Index([ModelBinder(typeof(AModelDataBinder))]AModel input) {
source share