LazyZebra
LazyZebra

Reputation: 1113

MVC DisplayFormat doesn't apply for TextBoxFor

I have a currency Model decorated with [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")], it does work (The $ sign is displayed) for DisplayFor, but not for TextBoxFor in the View.

May be this is a wrong approach for this case and I'd rather go with some JQuery solution, but I am wondering if there's a "framework way"...

Thanks in advance.

Upvotes: 1

Views: 3411

Answers (1)

Display Name
Display Name

Reputation: 4732

You can define EditorTemplate for TextBox and override its behavior any way you want, in your example just to show it as currency (if I understood your motives correctly). I think its simpler than jQuery and its a "framework way" as you called it.

There is great example on how to do it here: Currency Formatting MVC

Hope this helps, please let me know if not.

Upvotes: 1

Related Questions