Client side Drop down validation using jQuery.
For the textbox MVC will write JavaScript
for Required, RegularExpression
& StringLength attributes but there is no built-in method to validate a
drop down menu, we need to define our own method.
First we need to define a method to
validate dropdown control and define rules for each dropdown controls.
To display your error message still you
need to defile required attribute on your property and include validation
summery on your page. E.g.
jQuery.validator.addMethod(
"selectNone",
function(value, element) {
if (element.value == "")
{
return false;
}
else return true;
},
"Please select an option."
);
$(document).ready(function() {
$("#form0").validate({
rules: {
"Title.TitleID": {
selectNone: true
},
"SecretQuestion.IntCode":{
selectNone: true
}
}
});
});
For more details click here or for more jQuery
validation click here
About Hasmukh patel

- Hasmukh Patel
- Harrow, London, United Kingdom
- Dot-Net developer with expertise in Web, WPF, Win-form applications. Have worked on Asp.net,mvc , WPF and Win-forms projects in c#.net language having Sql-Server/Oracle as database with service oriented architecture using test driven development. Having complete knowledge of SDLC and have successfully worked and implemented it on projects.