自定义强类型助手
我使用自定义助手时遇到错误:
CS1593:委托“System.Action”不接受 1 个参数
这是视图代码:
@Html.BsLookUp(Model => Model.FieldId, Model.FieldDescription)
和助手:
public static MvcHtmlString BsLookUp<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string initialText)
{
string fieldName= ExpressionHelper.GetExpressionText(expression);
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
StringBuilder sb = new StringBuilder("");
sb.AppendFormat("<input type='text' name='{0}' value='{1}'/>", campo, initialText);
return MvcHtmlString.Create(sb.ToString());
}
如果我直接在视图中传递字符串,则此工作有效:
@Html.BsLookUp(Model => Model.HandleMotivoglosa, "any text here..")
I´m getting errors using my custom helpers:
CS1593: Delegate 'System.Action' does not take 1 arguments
Here is the view code:
@Html.BsLookUp(Model => Model.FieldId, Model.FieldDescription)
And the helper:
public static MvcHtmlString BsLookUp<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, string initialText)
{
string fieldName= ExpressionHelper.GetExpressionText(expression);
ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
StringBuilder sb = new StringBuilder("");
sb.AppendFormat("<input type='text' name='{0}' value='{1}'/>", campo, initialText);
return MvcHtmlString.Create(sb.ToString());
}
if I pass a string directly in my view this works:
@Html.BsLookUp(Model => Model.HandleMotivoglosa, "any text here..")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否注意到:
该错误似乎很晦涩,但请尝试将代码更改为:
Have you noticed:
The error seems quite obscure, but try changing your code to: