razor - ASP.NET - Get DisplayNameFor model outside the view -


in have typed view of :

@model modellib.client 

but further down code want displaynamefor of property another model, precisely modellib.licence model.

normally, typed model :

@html.displaynamefor(model => model.prop) // client 

any ideas ?

(in response comments above...)

just use property on nested model. single instance, this:

@html.displaynamefor(model => model.somelicense.someproperty) 

for collection of instances, parent model has collection of nested model, can refer instance in collection:

@html.displaynamefor(model => model.somelicenses.first().someproperty) 

it may appear call first() fail in event there 0 elements, never actually invokes first() in case. reference used framework might call "some reflection trickery" type information can reference attributes on property.


Comments