Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would this partial view return a blank?

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"); }
like image 437
Mike Wills Avatar asked Mar 15 '26 01:03

Mike Wills


1 Answers

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"); }
like image 98
Gabriele Petrioli Avatar answered Mar 18 '26 08:03

Gabriele Petrioli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!