Organizational Research By

Surprising Reserch Topic

mvc3 dropdownlist not validating with required class field as type int using -'asp.net,asp.net-mvc,asp.net-mvc-3'


mvc3 dropdownlist not validating with required class field as type int  using -'asp.net,asp.net-mvc,asp.net-mvc-3'

Any idea why the following dropdownlist won't validate with required field as type int (the "Title" field below)?

    [Required]             // This works!
    [Display(Name = "Name")]
    public string Name { get; set; }

    [Required]             // This doesn't work
    [Display(Name = "Title")]
    public int TitleId { get; set; }



     <div class="editor-label">
        @Html.LabelFor(model => model.Name, "Name")
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name, "This can't be blank!")
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.TitleId, "Title")
    </div>
    <div class="editor-field">
         @Html.DropDownListFor(model => model.TitleId, (SelectList)ViewBag.TitleId, String.Empty)
        @Html.ValidationMessageFor(model => model.TitleId)
    </div>



    
asked Sep 7, 2015 by rajesh
0 votes
23 views



Related Hot Questions



Government Jobs Opening


...