I've looked around the web for a while, but can't find a good solution to my specific issue. I'm working on a MVC3 Razor app. I'm doing a bunch of stuff on the client side with jQuery as well so in this case I need my input fields to have html Id attributes.
In this specific issue when I use a TextBoxFor to display a currency (type is decimal), the value renders with 4 decimal places (I only want 2). I put in the model attribute
[DisplayFormat(DataFormatString = "{0:n2}", ApplyFormatInEditMode = true)]
When it renders it seems to ignore this "displayFormat". I've seen other posts online confirming that this problem exists with the TextBoxFor html helper.
On the other hand, I can change to use an EditorFor html helper and the DisplayFormat model attribute works for formats my textbox value to 2 decimal places. The down-side is I loose the ability to apply html attributes to my html helper which I need for jQuery. What is the best way to get the best of both worlds? I've seen a bunch of workarounds, but it seems like there must be an easier way to do this.
As a side note, my specific project requires most of my fields to have html Id attributes and sometimes classes so I can perform client side jQuery operations. Not sure if this means I should focus on extending the EditorFor html helper to also accept html attributes or not.