Let's say that you have a Model that looks kind of like this:
public class MyClass {
public string Name { get; set; }
public DateTime MyDate { get; set; }
}
The default edit template that Visual Studio gives you is a plain textbox for the MyDate
property. This is all fine and good, but let's say that you need to split that up into it's Month/Day/Year components, and your form looks like:
<label for="MyDate">Date:</label>
<%= Html.TextBox("MyDate-Month", Model.MyDate.Month) %>
<%= Html.TextBox("MyDate-Day", Model.MyDate.Day) %>
<%= Html.TextBox("MyDate-Year", Model.MyDate.Year) %>
When this is submitted, a call to UpdateModel
won't work, since there isn't a definition for MyDate-Month
. Is there a way to add a custom binder to the project to handle situations like this, or if the HTML inputs are named differently (for whatever reasons)?
One workaround I've found is to use JavaScript to inject a hidden input into the form before submission that concatenates the fields and is named properly, but that feels wrong.