asp.net mvc - how does mvc HtmlHelper DisplayFor function extract the full property path from the lambda function? -


i see mvc finding names of variables passed lambda function in html.displayfor method:

@html.hiddenfor(model => mymodel.propa.propb) 

could generate html like:

<input id="mymodel_propa_propb" type="hidden" value="" > 

it using reflection, beyond me. fill me in?

also, possible create html helper function takes property reference instead of lambda function accomplish similar? ie.

@html.hiddenfor(mymodel.propa.propb) 

...and helper passed full "mymodel.propa.propb" reference , not value of propb? lambda function odd .net workaround accomplish sort of task or preferred approach across programming disciplines.

actually, traversing expression tree pass helper method in order property names. in practice, like:

memberexpression memberexpression = (memberexpression) expression.body; propertyname = memberexpression.member.name; 

of course not complete - instance, have walk chain of expressions when there multiple property invocations in expression passed in, have account other expression types being passed in memberexpression, etc., etc. - idea. remember expression code expression represented data. also, since mvc open source, exact code use arrive @ html name in sources, if want.

to address second question, answer no. passing "just property" without lambda (which expression<func<t,object>>), not work, because function can see value passed in - , nothing how calling code arrived @ value.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -