0

I try to use the jQuery Validation Unobtrusive Native with bootstrap and ASP:NET MVC 5 (https://github.com/johnnyreilly/jQuery.Validation.Unobtrusive.Native)

All validation work fine (textbox, textarea, checkbox) except for dropdownlist multiselect. This is my model:

public class Register

[Display(Name = "Languages")]
[Required(ErrorMessage = "Please select a langauge")]
public List<int> SelectedLanguages { get; set; }


public List<Language> Languages { get; set; }

and this my view

<div class="form-group">
 @Html.LabelFor(m => m.SelectedLanguages, new { @for = "submit-languages" })
 @Html.DropDownListFor(m => m.SelectedLanguages, true, new SelectList(Model.Languages, "Id", "Name"), htmlAttributes: new { @id = "submit-languages", @multiple = "multiple", @title = "-" })
</div>

the html generated is:

<select class="input-validation-error" data-msg-required="Please select a langauge" data-rule-required="true" id="submit-languages" multiple="multiple" name="SelectedLanguages" title="-" aria-required="true" style="display: none;">
    <option value="1">Italian</option>
    <option value="2">French</option>
    <option value="3">German</option>
    <option value="4">Spanish</option>
    <option value="5">Russian</option>
    <option value="6">Arabic</option>
    <option value="7">Ukrainian</option>
</select>

but the validation message does not appear...

hanc
  • 121
  • 8
  • Not related, but what is the point of changing the `id` attribute of your ` –  Oct 12 '15 at 22:10
  • And the html you have shown has `style="display: none;` so its not visible. Are you using a plugin? (by default hidden form elements are not validated) –  Oct 12 '15 at 22:11
  • the select was hidden from bootstrap framework for generate your html and styling the dropdownlist. if i use a normal html select object without bootstrap...work fine. – hanc Oct 12 '15 at 22:33
  • I'm not familiar with Unobtrusive Native, but I assume it uses `jquery.validate`. By default hidden inputs are not validated so you will not get a client side validation error. You can override the default behavior - [refer this answer](http://stackoverflow.com/questions/32500494/jquery-validate-on-html-dropdownlistfor-with-bootstrap-selectpicker/32501890#32501890) for an example –  Oct 12 '15 at 22:39

0 Answers0