-1

Why is my strongly type html having a data-val-required attribute even though I didn't specified in my model property to be required? Here is my model class

public class Document
{
    public string Name { get; set; }
    public bool IsConfirmed { get; set; }
}

Here is the html being rendered:

<input class="full-width" data-val="true" data-val-required="The IsConfirmed field is required." id="Document_0__IsConfirmed" name="Document.IsConfirmed" type="checkbox" value="true" title="" autocomplete="off" />
<input name="Document.IsConfirmed" type="hidden" value="false" />

Your help will be much appreciated.

Bon Macalindong
  • 1,310
  • 13
  • 20
  • 1
    Because its typeof `bool` which must always have a value (`true` or `false`). If it was `bool?` then the `data-val` attributes would not be rendered –  Sep 24 '15 at 09:06
  • Hi Stephen, Thanks for that, didn't thought of that before I asked the question :) – Bon Macalindong Sep 24 '15 at 09:22

1 Answers1

0

Change your model to this

public class Document
{
    public string Name { get; set; }
    public Nullable<bool> IsConfirmed { get; set; }
}
Ubiquitous Developers
  • 3,637
  • 6
  • 33
  • 78