asp.net mvc 3 - How to access other Model field in custom Model field attribute? -


the problem i'm trying create custom model field attribute in asp.net mvc3 needs access other model field. named example "personid".

so have model

public class personwoundmodel : iappointmentmodel     {          public int personid { get; set; }          [customattribute("personid")]         public fillinlist positions { get; set; } } 

and have custom attribute

[attributeusage(attributetargets.field | attributetargets.property, allowmultiple = false)]     public class customattribute : attribute, imetadataaware     {         public int personid { get; private set; }           public customattribute(bool allowdelete, bool allowedit, string htmlhelpers)         {            //i need personid here somehow.. reflection or other method.         } } 

so basicaly need apersonid field in [customattribute] further usage. thinkin using reflection have no idea how model object there. thanksa lot guys.

you cannot - because there no model object.

your attribute 'serialized' in metadata - i.e. fields needed construct serialized have compile time known literals. constructor called when use reflection on model class using method getcustomattributes. @ point you(in code) have object deal with.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -