0

I am working with this book from Apress. Pro ASP.NET MVC 2 Framework, Second Edition, Updated. I am in chapter 5 SportsStore: Navigation and Shopping Cart at the point where I add this line to the Site Master.

   <% Html.RenderAction("Menu", "Nav"); %>

Running the project generates an error. CS0103: The name 'Html' does not exist in the current context

I am using Visual Studio 2010 and the project is using Framework 4.0.

Every thing to this point in the book worked fine. Now I cannot get page this. Does anyone know how to fix this error. These are the name spaces added to the 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 listing.

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

1
  • I suspect some assembly is missing. Commented Sep 24, 2013 at 7:18

2 Answers 2

3

I see that your master inherits from SportsStore.WebUI.Views.Shared.Site which is a custom class. Make sure that this custom class derives from System.Web.Mvc.ViewMasterPage so that the Html property is defined.

Sign up to request clarification or add additional context in comments.

2 Comments

Look like I cannot simply replace the line "public partial class Site: System.Web.UI.MasterPage iwth public partial class Site: System.Web.Mvc.ViewMasterPage. I also tried public partial class Site: System.Web.UI.MasterPage, System.Web.Mvc.ViewMasterPage but that would not compile. Can you show me the code? Thanks.
I contacted apress and they told me where to download the code from the book. Again the book is Pro ASP.NET MVC 2 Framework, Second Edition, Updated. After downloading the code, I found I had to remove the Site.Master code behind and designer files from the project. I also had to change the site.master to inherit the System.Web.Mvc.ViewMasterPage. Thanks Chirag for your time.
0

Reolution. I contacted apress and they told me where to download the code from the book. Again the book is Pro ASP.NET MVC 2 Framework, Second Edition, Updated. After downloading the code, I found I had to remove the Site.Master code behind and designer files from the project. I also had to change the site.master to inherit the System.Web.Mvc.ViewMasterPage. Thanks Chirag for your time. – pary just now edit

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.