Possible Duplicate:
How to filter form data with custom model binder
The simple model below pre-populates fields as desired in an edit/create view (i.e., $250,000 & 75%). However, when posting back into the controller, the properties fail to bind properly.
What is the most simple way to get MVC to convert those strings from human friendly format back into decimal and float property values? Can I use some sort of ValueConverter attribute on my properties? Or do I have to implement a full up ModelBinder?
public class MyModel
{
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:C0}")]
[Required]
[Display(Name = "My Money")]
public decimal Moo { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:0%}")]
[Required]
[Display(Name = "Percentage of Awesomeness")]
public float PercentAwesome { get; set; }
}
I had assumed incorrectly that the MVC Runtime would be able to handle it automagically by using the values in the DisplayFormat attribute.
Thanks in advance from an MVC newbie!