asp.net mvc 2 - Can I get to the containing Model of a property in an MVC2 Html Helper -
i have html helper following signature:
public static mvchtmlstring uiautocompleteforwithid<tmodel, tproperty>(this htmlhelper<tmodel> helper, expression<func<tmodel, tproperty>> expression, object htmlattributes)
i understand how hands on value of passed in member , it's metadata, there anyway access containing model, or more value of particular sibling member (a property) of passed in member name?
cheers, matthew
edit: ok think can using modelmetadata.fromstringexpression method (sometimes takes asking before see eh?), best way go this?
if need access value of sibling member means assume view model has sibling member. means html helper no longer needs generic. this:
public static mvchtmlstring uiautocompleteforwithid<tproperty>( htmlhelper<myviewmodel> helper, expression<func<myviewmodel, tproperty>> expression, object htmlattributes ) { myviewmodel model = helper.viewdata.model; var value = model.someothersiblingproperty; // todo: property ... }
or if view models implement common base interface contains sibling member in question specify generic constraint:
public static mvchtmlstring uiautocompleteforwithid<tmodel, tproperty>( htmlhelper<tmodel> helper, expression<func<tmodel, tproperty>> expression, object htmlattributes ) tmodel: isomeinterface { isomeinterface model = helper.viewdata.model; var value = model.someothersiblingproperty; // todo: property ... }
Comments
Post a Comment