Modify post data with a custom MVC extension?

Posted by Jaxidian on Stack Overflow See other posts from Stack Overflow or by Jaxidian
Published on 2010-03-30T02:49:18Z Indexed on 2010/03/30 2:53 UTC
Read the original article Hit count: 289

Filed under:
|

So I'm looking into writing some custom MVC extensions and the first one I'm attempting to tackle is a FormattedTextBox to handle things such as currency, dates, and times. I have the rendering of it working perfectly, formatting it, working with strong types and everything all golden. However, the problem I'm now running into is cleaning up the formatted stuff when the page posts the data back.

Take for example, a currency format. Let's use USD for these examples. When an object has a property as a decimal, the value would be 79.95. Your edit view would be something like:

<%= Html.FormattedTextBox(model => Model.Person.HourlyWage, "{0:C}") %>

This is all well and good for the GET request, but upon POST, the value is going to be $79.95, which when you assign to that decimal, gets unhappy very quickly and ends up shoving a 0 in there.

So my question is, how do I get code working somewhere to work with that value before the MVC Framework goes and starts shoving it back into my ViewModel? I'd much rather this be done server-side than client-side.

Thanks!!

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2