I'd like to know if it's possible to make a Func<dynamic, string>
become Expression<Func<dynamic, string>>
?
I have the following code in my .cshtml file (it's an example, not the whole code).
@Html.CreateSomeThing(
@<text>
@TextBoxFor(model=> model.Id)
<span> some html here </span>
@DropDownListFor(model => model.Persons)
</text>);
In the .cs file i have the following:
public void CreateSomeThing<TValue>(Func<dynamic, object> description = null) {
//method body
}
What i'm trying to do is: Get all the expressions inside each @TextBoxFor
, and @DropDownListFor
. In this case i'd like to get the values from (model.Id
and model.Persons
). I know that it's possible by using Expression<Func<dynamic,string>>
But if i try to change Func<dynamic, object>
to Expression<Func<dynamic, string>>
I get the error:
Expression lambda cannot have a Body