为什么我的自定义 HtmlHelpers 在升级到 MVC3 后停止工作?
我刚刚完成了将我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试在视图顶部添加一个
Import
指令,看看是否有任何区别:您也可以将此命名空间添加到 web.config 的
部分。Try adding an
Import
directive on the top of the view to see if it makes any difference:Also you could add this namespace to the
<namespaces>
section of web.config.