I derive the controllers from a base class:
namespace merawi.Controllers
{
public class BaseController : Controller
{
public CultureInfo trTR = new CultureInfo("tr-TR");
public BaseController()
{
trTR.NumberFormat.CurrencySymbol = "TL";
}
}
}
and use this statement to format the currencies:
ViewBag.SellingPrice = sp.ToString("C", trTR);
However, in the views which has viewmodels like
@model List<merawi.Models.DocumentWorkStep>
I need a way to format the currencies as desired.
SellingPrice
is a decimal field in the DocumentWorkStep
class:
public Nullable<decimal> SellingPrice { get; set; }
and using this
<td>@string.Format("{0:C}", res.SellingPrice)</td>
outputs ₺, I need "TL"
I need a way to access the trTR object from the view files...
Thanks
Add this to your web.config file, assuming that you want the same culture to be used in your entire application:
<configuration>
<system.web>
<globalization uiCulture="tr-TR" culture="tr-TR" />
</system.web>
</configuration>
In my case, I add the globalization tag in the web.config file, also, since we need to customize the culture format(such as using "."
instead of ","
as decimal in FR-CA
), I add a customization in Global.asax.vb, which can set the globalization globally.
Web.config:
<globalization culture="fr-CA" uiCulture="fr-CA"/>
Global.asax.vb:
Private Sub MvcApplication_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.BeginRequest
StartSession()
Dim info as new Globalization.CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.ToString())
info.NumberFormat.CurrencyDecimalSeparator = "."
info.NumberFormat.NumberDecimalSeparator = "."
info.NumberFormat.PercentDecimalSeparator = "."
info.NumberFormat.CurrencyGroupSeparator = ","
info.NumberFormat.NumberGroupSeparator = ","
info.NumberFormat.PercentGroupSeparator = ","
info.NumberFormat.
System.Threading.Thread.CurrentThread.CurrentCulture = info
End Sub
That's my case. Hopefully it helps. Thank you.