Required Attribute to AjaxDropDown

Aug 9, 2011 at 2:34 PM

How to validate atleast one item in the drop down list has been selected or not using Required Attribute ?

Coordinator
Aug 9, 2011 at 3:47 PM

put the Required Attribute above the property

this is shown in the live demo

Aug 11, 2011 at 7:23 AM
I Given Required Attribute.

Data is loading properly. But Validation is not happening. When I checked with Live Demo .chtml and mine,
the following JAvascript is not getting added.

<script type="text/javascript">
//<![CDATA[
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }
window.mvcClientValidationMetadata.push({"Fields":[{"FieldName":"Country","ReplaceValidationMessageContents":true,"ValidationMessageId":"Country_validationMessage","ValidationRules":[{"ErrorMessage":"The Country field is required.","ValidationParameters":{},"ValidationType":"required"},{"ErrorMessage":"The field Country must be a number.","ValidationParameters":{},"ValidationType":"number"}]}],"FormId":"form0","ReplaceValidationSummary":false});
//]]></script>

I added in my Global.asax,
 ModelMetadataProviders.Current = new AwesomeModelMetadataProvider();

To make the validation work, what else has to be checked ?
Coordinator
Aug 11, 2011 at 7:26 AM

probably you're using the unobtrusive stuff, that's why it's not working (the client side ) the server side should work

Aug 11, 2011 at 7:53 AM

Yes. I am using the following scripts

  @Html.JsFile("jquery.validate.unobtrusive.js", "jquery_validate_unobtrusive_5")
 @Html.JsFile("jquery.unobtrusive-ajax.js", "jquery_unobtrusive-ajax_6")

whether this will create issue ?

Coordinator
Aug 11, 2011 at 11:02 AM

it's not going to work with unobtrusive