I’m using MVC3 with a detailed view that needs to display a formatted dollar amounts like $1,200.00. The controller is passing in a double value in this case for MonthlyMortgage to the view. The line of code below however, does not display the correct string formatting. What is displayed is $1200.00, and what I need is $1,200.00.
I have tried:
$@String.Format("{0:c}", Html.DisplayFor(model => model.MonthlyMortgage))
and I have tried this:
$@String.Format("{0:#,###,###,##0.000}", Html.DisplayFor(model => model.MonthlyMortgage))
Can someone please enplane why this is not working?
You don’t need to use
Html.DisplayForbecause it will returnMvcHtmlStringso thestring.Formatdoesn’t apply.Just use the
string.Formaton your model:Note you don’t need the ‘$’ sign anymore because the
{0:c}will take care of it.