Sunday, 11 August 2013

"The field must be a number", but my field is optional

"The field must be a number", but my field is optional

I'm using ASP.NET MVC4 for a new app. I'm pretty new to it and am
struggling with something that should be easy, but can't get it to work.
I have a int? field on my database. My EF code first model has this:
public int? Effort { get; set; }
The above line is also in my viewmodel. This is in the view:
<div class="editor-label">
@Html.LabelFor(model => model.Effort)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Effort, new { @class="wide100" })
@Html.ValidationMessageFor(model => model.Effort)
</div>
When I try to save the record without any input in for Effort, I get this
error: "The field Effort must be a number."
Why is that? My field is optional.
Same error shows if I use alpha characters, but that is as expected.

No comments:

Post a Comment