jquery - Client Site Custom Validation on MVC 4 -


i have database generated model user.

public partial class user: {     [datamember]     public int id { get; set; }      [datamember]     public nullable<int> userid      [datamember]     public string username {get; set; }      [datamember]     public nullable<phone> {get; set; } } 

then created wrapper class on database user generate:

[metadatatype(typeof(userattributes))] public class cuser : user {    public nullable<bool> isrequire {get; set} } 

now have 2 option on view "save , close" , "submit". have added 1 more property on wrapper class "isrequire". when click on submit button should validate require field @ time, , when click on save , close should bypass these field. can't change approach, working fine server side example of fields have 100's field , basis of condition.

and create customattribute class

public class userattributes {     [required]     public nullable<bool> isrequiredif { get; set; }      [requiredif(isrequiredpropertyname = "isrequiredif", errormessage = "required field.")]     public int id { get; set; }      [requiredif(isrequiredpropertyname = "isrequiredif", errormessage = "required field.")]     public nullable<int> userid      [requiredif(isrequiredpropertyname = "isrequiredif", errormessage = "required field.")]     public string username {get; set; }      [requiredif(isrequiredpropertyname = "isrequiredif", errormessage = "required field.")]     public nullable<phone> {get; set; } } 

and add metadata reference on cuser class, add 1 more class custom validation "requireif"

[attributeusage(attributetargets.field | attributetargets.property, allowmultiple = false, inherited = true)] public class requiredif : validationattribute//, iclientvalidatable {     public string isrequiredpropertyname { get; set; }      protected override validationresult isvalid(object value, validationcontext validationcontext)     {         // logic     }      public ienumerable<modelclientvalidationrule> getclientvalidationrules(modelmetadata metadata, controllercontext context)     {         // logic call client side function.     }  } 

issue: when have added client side function not calling. how can debug , how work, please guide me on right direction.

(function ($) {  jquery.validator.unobtrusive.adapters.add("requiredif", ['isrequiredpropertyname'], function (options) {     options.rules['requiredif'] = { other: options.params.other,         isrequiredpropertyname: options.params.isrequiredpropertyname     };     options.messages['requiredif'] = options.message; });  jquery.validator.addmethod('requiredif', function (value, element, parameters) {      alert(isrequiredpropertyname);      var result = false;     return result;  });  } (jquery)); 


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -