p cary
p cary

Reputation: 11

Why am I getting an error using Html.RenderAction. CS0103: The name 'Html' does not exist in the current context

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>

Upvotes: 0

Views: 1363

Answers (2)

p cary
p cary

Reputation: 11

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

Upvotes: 0

Chirag Arvadia
Chirag Arvadia

Reputation: 1200

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.

Upvotes: 3

Related Questions