I am trying to use Expression> expression, sent in to my helper class.
I want to pull the value form it and render it in a html string. I can't seem to get it working i currently have:
public static MvcHtmlString TextboxGroupStaticFor(
this HtmlHelper html,
Expression> expression,
BootstrapInputSizes? width = BootstrapInputSizes.Defalut
)
{
var placeholder = string.Empty;
if (html.ViewData.ModelMetadata.AdditionalValues.ContainsKey("placeholder"))
{
placeholder = html.ViewData.ModelMetadata.AdditionalValues["placeholder"] as string;
}
var sb = new StringBuilder();
sb.AppendLine("
sb.AppendLine(html.LabelFor(expression).ToHtmlString());
sb.AppendLine("
" + " " + "
");sb.AppendLine("
return new MvcHtmlString(sb.ToString());
}
Called using: @Html.TextboxGroupStaticFor(x=> x.Name);
But can't work out how to do expression.value or something like that?
UPDATE
I found this works
Func method = expression.Compile();
TProperty value = method(html.ViewData.Model);
Is this a good way e.g performance wise?