【发布时间】:2018-03-23 16:09:19
【问题描述】:
我做了这个自定义助手:
public static System.Web.Mvc.MvcHtmlString RzTextBoxForCNPJ<TModel, TValue>(this System.Web.Mvc.HtmlHelper<TModel> html,
System.Linq.Expressions.Expression<System.Func<TModel, TValue>> expression)
{
System.Collections.Generic.Dictionary<string, object> htmlAttributes = new System.Collections.Generic.Dictionary<string, object>();
htmlAttributes.Add("class", "form-control cnpj");
return (html.TextBoxFor(expression, htmlAttributes));
}
为了避免需要将类属性添加到特定类型的字段。
但是。使用此助手时:
@RzHelpers.RzTextBoxForCNPJ(model => model.Cnpj)
我收到了这个错误:
CS7036:没有给出与“RzHelpers.RzTextBoxForCNPJ(HtmlHelper, Expression>)”所需的形参“表达式”相对应的参数
好像我传递了错误的类型或数量的参数。
它不是我的第一个助手,并且永远不必传递第一个参数,只能从第二个开始。
我忘记了什么?
【问题讨论】: