【发布时间】:2010-03-29 18:06:53
【问题描述】:
我们正在阅读一本 ASP.Net MVC 书籍,并且在使用我们视图中的扩展方法时遇到了麻烦。 Extension 方法如下所示:
using System;
using System.Runtime.CompilerServices;
using System.Web.Mvc;
namespace MvcBookApplication
{
public static class HtmlHelperExtensions
{
public static string JQueryGenerator(this HtmlHelper htmlHelper, string formName, object model);
}
}
我们在视图中使用扩展方法是这样的:
<%=Html.JQueryGenerator("createmessage", ViewData.Model)%>
问题是,那行代码说 JQueryGenerator 不是 HtmlHelper 的公认方法。我相信我们已经在 web 项目中设置了正确的引用,但是我们可以检查其他的东西吗?视图没有 using 语句,是吗?
【问题讨论】:
-
正如 Gregoire 所说,您可以在 web.config 中添加 MvcBookApplication 命名空间,方法是在其中添加
web.config 中的 system.web 部分,或者您可以将 放在包含对辅助方法调用的视图的开头。
标签: asp.net-mvc extension-methods html-helper