【发布时间】:2015-01-02 22:11:06
【问题描述】:
我正在使用 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>)”的类型参数。尝试明确指定类型参数。
我试过了
@Html.SpecialTextBoxFor(m => m.Category[i].Name)
点之后,找不到Category
在我的 web.config 中,我有正确的设置:
<compilation debug="true" targetFramework="4.5" />
根据一些帖子,我尝试将其重置为 4.5.1,但没有任何变化。
我确认我在 web.config 视图中对我的命名空间有正确的引用:
<add namespace="MyApp" />
我的 global.asax.cs 中也有这个
ViewEngines.Engines.Add(new RazorViewEngine());
我还应该尝试什么!?
【问题讨论】:
-
尝试将减速改为:this HtmlHelper
htmlHelper, -
有效,将其发布为答案,我会标记它。谢谢!
标签: c# asp.net asp.net-mvc-4 html-helper