asp.net mvc 2 - Dynamic validation on MVC 2 -
this works fine
[metadatatype(typeof(area_validation))] public partial class area { ... } public class area_validation { [required(errormessage = "please add field.")] public int email { get; set; } [required(errormessage = "please add field")] public string name { get; set; } }
but how about if area_validation
dynamically created? example subscription fields on back-end can created user , end this:
how can set metadata on each field auto validation?
currently i'm doing:
public class subscriberformviewmodel { public list<subscriberfieldmodel> fields { get; private set; } public calendar calendar { get; private set; } public company company { get; private set; } public subscriberformviewmodel() { // todo: testing while validation not set } public subscriberformviewmodel(decimal calendarid) { if (calendarid > 0) { subscribersrepository db = new subscribersrepository(); calendar calendar = db.getcalendarbyid(calendarid); company company = db.getcompanybyid(calendar.company_id); this.fields = db.findallsubscriberfieldsbycalendar(calendarid); this.calendar = calendar; this.company = company; } else this.fields = new list<subscriberfieldmodel>(); } }
and want set metadata in fields
property
in other words, fields
filled database , can have several types, can string
, number
, dropdown
, etc ... kinda mailchimp fields properties:
is there way programmaticaly or need create jquery plugin validate , stop using use validation mvc2 ?
thank you
i dont think can using data annotations attributes.
there project in codeplex, called fluent validation permit add validation rules in fluent way using .net code. never used project seems maybe can in case dynamically created objects.
hope helps!
Comments
Post a Comment