升级到MVC3后,为什么我的自定义HtmlHelpers停止工作?

时间:2011-02-23 22:32:59

标签: asp.net-mvc asp.net-mvc-2 asp.net-mvc-3 views html-helper

我刚刚完成了这个清单,将我的asp.net mvc2网站升级到mvc3:http://www.asp.net/learn/whitepapers/mvc3-release-notes#upgrading

一切都在编译,但是当我运行应用程序时,我在视图中出现错误。

示例视图:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/site.Master" Inherits="System.Web.Mvc.ViewPage<Genesis.Domain.Entities.StreamEntry>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%: Model.seTitle %>
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
    <%: Html.GetMetaTag("description", Model.seDescription )%>
    <%: Html.GetMetaTag("keywords", Model.seKeywords )%>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="HeadlineContent" runat="server">
    <%: Model.seHeadline %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p>
        <%//: Html.AddThis() %>
    </p>
    <p>
        Created: <br /><strong><%: Model.seDateCreated %></strong><br />
        Last Modified: <br /><strong><%: Model.seDateModified %></strong>


    </p>
    <%: MvcHtmlString.Create(Model.seBody) %>

    <% Html.RenderAction("Comments", "Comments", new { streamEntryID = Model.seID, allowComments = Model.AllowComments }); %>

</asp:Content>

错误文字:

Compilation Error 
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<Genesis.Domain.Entities.StreamEntry>' does not contain a definition for 'GetMetaTag' and no extension method 'GetMetaTag' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<Genesis.Domain.Entities.StreamEntry>' could be found (are you missing a using directive or an assembly reference?)

Source Error:



Line 6:  
Line 7:      <asp:Content ID="Content3" ContentPlaceHolderID="MetaContent" runat="server">
Line 8:          <%: Html.GetMetaTag("description", Model.seDescription )%>
Line 9:          <%: Html.GetMetaTag("keywords", Model.seKeywords )%>
Line 10:     </asp:Content>

如何让我的观点再次识别我的自定义html助手?

1 个答案:

答案 0 :(得分:3)

尝试在视图顶部添加Import指令,看看它是否有所不同:

<%@ Import Namespace="Namespace.Of.The.Class.Containing.The.Helper" %>

此外,您可以将此命名空间添加到web.config的<namespaces>部分。