继续得到"无法推断"尝试调用我的htmlhelper时出错

时间:2015-01-02 22:11:07

标签: c# asp.net asp.net-mvc-4 html-helper

我正在使用Visual Studio Express 2013 for Web和Framework 4.5。 我的Index.view称之为部分视图:

@Html.Partial("_MyCategories", Model)

我的模型在局部视图中引用:

@using MyApp.ModelHelpers
@model MyApp.Models.MyViewModel

在局部视图中,我试图在模型中的循环内调用htmlHelpers类:

@Html.SpecialTextBoxFor(Model.Category[i].Name)

并且在htmlHelpers类中我有这个方法:

public static MvcHtmlString SpecialTextBoxFor<TModel, TProperty>(this HtmlHelper htmlHelper, Expression<Func<TModel, TProperty>> expression)

当我尝试使用以下方法从局部视图调用我的htmlhelper时:

@Html.SpecialTextBoxFor(Model.Category[i].Name)

我收到此错误: 无法从用法中推断出方法“MyApp.HtmlHelpers.SpecialTextBoxFor(System.Web.Mvc.HtmlHelper,System.Linq.Expressions.Expression&gt;)”的类型参数。尝试明确指定类型参数。

我试过了

@Html.SpecialTextBoxFor(m => m.Category[i].Name)

点后,找不到类别

在我的web.config中我有正确的设置:

<compilation debug="true" targetFramework="4.5" />

我尝试根据一些帖子将其重置为4.5.1,但没有变化。

我验证了我在视图web.config中对我的命名空间有正确的引用:

<add namespace="MyApp" />

我在global.asax.cs

中也有
ViewEngines.Engines.Add(new RazorViewEngine());

我还应该尝试什么??

1 个答案:

答案 0 :(得分:2)

您需要将扩展​​功能的声明更改为:

public static MvcHtmlString SpecialTextBoxFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
相关问题