MVC Tips

You can use the standard ASP.NET features in your MVC views. In this case, you call the String.Format method to display the UnitPrice field in a suitable form for a monetary amount. You just pass in the Model.UnitPrice value as the argument to the method call.
<%= String.Format(“{0:F2}”, Model.UnitPrice) %>

String class can also be used as a formatter in thextbox:

Unit Price:
<%: Html.TextBoxFor(model => model.UnitPrice, new {Value = String.Format(“{0:F2}”, Model.UnitPrice)})%>

Author: Pouya Panahy

Microsoft certified DevOps engineer with passion in analysing, designing and implementing solutions for Azure Cloud with hands-on experience in security and quality assurence.

Leave a Reply