I have a partial view that I am creating to apply a special format to some decimal numbers. Here is the partial view ("_Dollar"):
@model decimal?
@if (Model.HasValue)
{ Html.Display(Model.Value.ToString("$#,0.00;$#,0.00-;0.00")); }
else { Html.Display("0.00"); }
Here is the calling line of code:
<td style="text-align:right;">@Html.DisplayFor(modelItem => item.TotalBill, "_Dollar")</td>
Any ideas of what might be going on?
Update: I should add, when running debug, the partial view is called and runs as I would expect it to. To me, is seems the problem is with how I am using Html.Display.
Update: I understand based on @Gaby's answer why my previous trial doesn't work. I made the changes, but it still doesn't work. On my view I have @Html.Partial("_Dollar",item.TotalBill) in the partial view I now have:
@model decimal?
@if (Model.HasValue)
{ Html.Raw(Model.Value.ToString("$#,0.00;$#,0.00-;0.00")); }
else { Html.Raw("0.00"); }
Html.Display does not do what you think it does.. read http://msdn.microsoft.com/en-us/library/ee310180%28v=VS.98%29.aspx
You should use
@model decimal?
@if (Model.HasValue)
{ @Html.Raw(Model.Value.ToString("$#,0.00;$#,0.00-;0.00")); }
else { @Html.Raw("0.00"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With