asp.net mvc - How to get to the parent object in an editortemplate? -


in custom editor template want access parent object.

i'm using code not best way it, when using nested views:

object parent = viewcontext.controller.viewdata.model; 

does have better idea?

you shouldn't try climbing model hierarchy, if editor requires data add model or use viewdata. call render editor

<%: html.editorfor(model => model.editormodel, new {viewdatakeyname = model.additionaldata})%> 

be careful when adding data vital editor way, has included in each call template, that's why prefer include values in model itself.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -