Model Binding using different names in html markup and models
In an asp.net MVC 1.0 application I have the following action
public ActionResult Submit(ContactModel model)
{
ContentResult ret = new ContentResult();
//do something
return ret;
}
Where ContactModel is defined as:
public class ContactModel
开发者_如何学JAVA{
public string Name { get; set; }
public string Email { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public bool Authorization { get; set; }
}
Given that, in the Html Form that posts to this action, the names of the input tags are different from the names of the properties in the class ContactModel. Is there a way to map the html names to the class name so that the model binder can do its job?
The Bind Prefix (see How to use Bind Prefix?), can partially solve this problem although doesn't allow the definition of full aliases for each property. The Bind prefix has a strange behaviour though, because it assumes that between the prefix and the name there is a '.' (dot).
I don't think so.
You could create your own modelbinder though. See here for an example
精彩评论