In the Model, use like this:
[Required]
[DataType(DataType.Currency)]
[Display(Name = "Price", ResourceType = typeof(Resources.Language))]
public Decimal Price { get; set; }
In Views, use the Nuget Jquery Masked Input package, then you need to add a @section scripts
in your View:
@section scripts {
<script type="text/javascript">
$(function() {
$('#Price').maskMoney({ prefix: 'R$ ', allowNegative: false, thousands: '.', decimal: ',', affixesStay: false });
});
</script>
}
In fact, it is also good to inform the Web.config
on the culture used. It is not exactly necessary for this case, but it can serve the rest of the system well.
<configuration>
<system.web>
...
<globalization uiCulture="pt-BR" culture="pt-BR" enableClientBasedCulture="true" />
...
</system.web>
</configuration>