[RequiredIf("ValidationOption", CustomerParameter.Phone, ErrorMessageResourceType = typeof(Customer_cshtml), ErrorMessageResourceName = "PhoneRequired")] public string Phoner { get; set; } [RequiredIf("ValidationOption", CustomerParameter.Account, ErrorMessageResourceType = typeof(Customer_cshtml), ErrorMessageResourceName = "CustomerRequired")] public string Account{ get; set; } public CustomerParameter ValidationOption { get; set; }
$.validator.addMethod('requiredif', function (value, element, parameters) { var id = '#' + parameters['dependentproperty']; var targetvalue = parameters['targetvalue']; targetvalue = (targetvalue == null ? '' : targetvalue).toString(); var control = $(id); var controltype = control.attr('type'); --->//This line is getting undefined for EnumDropdownList property var actualvalue ; if (controltype === 'checkbox') { actualvalue = control.is(':checked').toString(); } else if (controltype === 'radio') { actualvalue = $('input[name='+parameters['dependentproperty']+']:checked').val() } else { actualvalue = control.val(); } if (targetvalue === actualvalue)--->///////In this comparison area targetvalue if fetching the name of the property like Phone or Account and the actual value is fetching the value of selected enums value like 0,1 etc so the rules are not getting added. return $.validator.methods.required.call( this, value, element, parameters); return true; } );
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)