1

I'm sure this is a simple problem but I can't seem to find it anywhere. Basically for input fields doing

<input asp-for="TotalSales" asp-format="{0:c}" class="form-control"/>

causes problems when saving the field as a decimal. I want to remove the currency symbol from the input and have it show up to the left of the input field using the proper localization for that symbol (so in the UK it displays £ instead of $). I can't quite seem to figure out how to do this in the view. Here is how the full code looks so far

<div class="form-group">
  <label asp-for="TotalSales" class="mobile-control-label"></label>
  <div class="col-xs-8">
    <div class="hasInputDiv">
      <input asp-for="TotalSales" asp-format="{0:c}" class="custom-form-control"/>
      <label asp-for="TotalSales" class="pc-control-label"></label>
    </div>
    <span asp-validation-for="TotalSales" class="text-danger"></span>
  </div>
</div>
Aaron
  • 21
  • 6
  • You are going to need to add localization to your project. https://msdn.microsoft.com/en-us/library/fw69ke6f.aspx – jgetner Jan 25 '18 at 22:34
  • I have the initial work for localization done, like having it initialized in the startup.cs and such just not any of the resource files generated since we haven't got to that part yet. I was hoping that asp.net had some built in functionality for currencies to work with. – Aaron Jan 25 '18 at 23:04

1 Answers1

1

Alright so I figured this out, basically you want do wrap the input in a span and add in a call to NumberFormatInfo to grab the current localization info's currency symbol. You will need to add using System.Globalization to the view. Hope this helps others struggling with currency symbols. Below is the input wrapped in a span to get it working.

<span>
  @NumberFormatInfo.CurrentInfo.CurrencySymbol
  <input asp-for="TotalSales" class="custom-form-control/>
</span>
Aaron
  • 21
  • 6