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

发布于 2024-10-18 22:48:59 字数 2536 浏览 1 评论 0原文

我刚刚完成了将我的 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 帮助程序?

I just finished going through this checklist to upgrade my asp.net mvc2 site to mvc3: http://www.asp.net/learn/whitepapers/mvc3-release-notes#upgrading

Everything is compiling, but when I run the application I get errors in the views.

Example View:

<%@ 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>

Error text:

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>

How do I get my views to recognize my custom html helpers again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沉溺在你眼里的海 2024-10-25 22:48:59

尝试在视图顶部添加一个 Import 指令,看看是否有任何区别:

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

您也可以将此命名空间添加到 web.config 的 部分。

Try adding an Import directive on the top of the view to see if it makes any difference:

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

Also you could add this namespace to the <namespaces> section of web.config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文