title: How to Format nullable decimal as currency in mvc 3 razor view for display purpose only
body: <p>I need help to format nullable decimal field as currency (with dollar sign and commas) in mvc application's razor view. Below is my modal and view code.</p>
  
  <p><strong>Model</strong>:</p>
  
  <pre><code>[Display(Name = "Eligible Amount")]
  [RequiredIfProjectEngineerSelected("ProjectEngineerId", "", ErrorMessage = "Eligible Amount field is Required")]        
  [DisplayFormat(DataFormatString = "{0:c}")]        
  public decimal? EligibleAmount { get; set; }
  </code></pre>
  
  <p><strong>View</strong>:</p>
  
  <pre><code>@{var formated = String.Format("{0:c}",  decimal)decimal.Parse(@Model.project.ProjectTotalCost.HasValue ? @Model.project.ProjectTotalCost.Value.ToString() : ""));}
  @Html.TextBoxFor(model =&gt; model.project.ProjectTotalCost, new { @Value = formatted})
  </code></pre>
  
  <p>It is displaying the formatted currency value in TextBoxFor control. But the problem what I am facing here is, when I am trying to update the value back, getting validation error saying "the value is not matching format".</p>