首页 > 代码库 > MVC 自定义 以表达式树为参数的htmlhelper

MVC 自定义 以表达式树为参数的htmlhelper

public static MvcHtmlString Try<TModel, TProperty>(    this HtmlHelper<TModel> htmlHelper,     Expression<Func<TModel, TProperty>> expression){    var builder = new TagBuilder("textarea");    builder.AddCssClass("ckeditor");    builder.MergeAttribute("cols", "80");    builder.MergeAttribute("name", "editor1");    builder.MergeAttribute("id", expression.Name); // not sure about the id - verify    var value =http://www.mamicode.com/ ModelMetadata.FromLambdaExpression(        expression, htmlHelper.ViewData    ).Model;    builder.SetInnerText(value.ToString());    return MvcHtmlString.Create(builder.ToString());}


参考凌鸢的文章。

MVC 自定义 以表达式树为参数的htmlhelper