Search code examples
c#entity-frameworkrazorhtml-helper

Cannot save property as decimal


In my model I use property.

[Display(Name = "Pensja")]
public decimal? Salary { get; set; }

In Edit Razor View I want to change value from 4000,00 to 4000,50. In View it looks like this.

<div class="form-group">
    @Html.LabelFor(model => model.Salary, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.Salary, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.Salary, "", new { @class = "text-danger" })
    </div>
</div>

I get the message that Salary must be a number. What I am doing wrong?


Solution

  • I assume that your error msg is on the client side (jscipt) and think your language is Polish, so you may need to configure few things related to your locale.

    Take a look to this url http://msdn.microsoft.com/en-us/library/gg674880(VS.98).aspx and https://weblogs.asp.net/scottgu/jquery-globalization-plugin-from-microsoft

    OR disable your clientside validation

      @{ Html.EnableClientValidation(false); }
        @Html.EditorFor(model => model.Salary, new { htmlAttributes = new { @class = "form-control" } })
        @{ Html.EnableClientValidation(true); }