我正在使用Apress的这本书。 Pro ASP.NET MVC 2 Framework,第二版,更新。 我在第5章SportsStore:导航和购物车中我添加的地方 这条线到Site Master。
<% Html.RenderAction("Menu", "Nav"); %>
运行项目会产生错误。 CS0103:当前上下文中不存在名称“Html”
我正在使用Visual Studio 2010,该项目正在使用Framework 4.0。
本书中关于这一点的每件事都运作良好。现在我无法得到这个页面。有没有人 知道如何解决这个错误。 这些是添加到webconfig的名称空间
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="SportsStore.WebUI.HtmlHelpers" />
</namespaces>
Full Site.Master列表。
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="SportsStore.WebUI.Views.Shared.Site" %>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<link rel="Stylesheet" href="~/Content/Site.css" />
<form id="form1" runat="server">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div id="content">
<div id="categories">
<% Html.RenderAction("Menu", "Nav"); %>
</div>
</asp:ContentPlaceHolder>
<div id="header">
<div class="title">SPORTS STORE</div>
</div>
</div>
</form>
答案 0 :(得分:3)
我看到你的主人继承自SportsStore.WebUI.Views.Shared.Site
这是一个自定义类。确保此自定义类派生自System.Web.Mvc.ViewMasterPage
,以便定义Html
属性。
答案 1 :(得分:0)
Reolution。 我联系了apress,他们告诉我从哪里下载代码。本书再次是Pro ASP.NET MVC 2 Framework,第二版,更新。下载代码后,我发现我必须从项目中删除Site.Master代码和设计器文件。我还必须更改site.master以继承System.Web.Mvc.ViewMasterPage。谢谢Chirag你的时间。 - 刚刚编辑