尝试调用我的 htmlhelper 时不断收到 "cannot be inferred" 错误

keep getting "cannot be inferred" error when trying to call my htmlhelper

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

@Html.Partial("_MyCategories", Model)

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

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

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

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

在 htmlHelpers class 我有这个方法:

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>)' 的类型参数。尝试明确指定类型参数。

我试过了

@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());

我还应该尝试什么!?

您需要将扩展​​函数的声明更改为:

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