Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have used dropdown list in mvc,and i need that dropdown list to be mandatory,i tried cutom validation but i m not able to get the validation message print.
Can anyone help with custom validations?
Posted
Comments
Kornfeld Eliyahu Peter 9-Mar-14 3:37am    
Please do not cross post. If someone knows the answer you will get it...
http://www.codeproject.com/Questions/740937/How-Do-I-Use-Auto-Suggestion-Drop-Down-In-Mvc

1 solution

You can use a jQuery for validation on the dropdown list

HTML
jQuery.validator.addMethod("requireddropdown", function (value, element, params) {
    var valid = false;
 if ($(element).val() != params.defaultvalue)
        valid = true;
    return valid;
});


In code add this above the getter and setter of the DropDownList

C#
[RequiredDropDown(ErrorMessage = "State is required.",DefaultValue="")]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900