Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error following along with ASP.NET and MVC 5... error CS0246: The type or namespace could not be found

Tags:

c#

asp.net-mvc

So I am following the examples in the book ASP.NET and MVC 5. Here is the view that results in the error:

@model SportsStore.WebUI.Models.ProductsListViewModel

@{
    ViewBag.Title = "Products";
}

@foreach (var p in Model.Products)
{
    <div>
        <h3>@p.Name</h3>
        @p.Description
        <h4>@p.Price.ToString("c")</h4>
    </div>
}

<div>
    @Html.PageLinks(Model.pagingInfo, x => Url.Action("List", new { page = x}))
</div>

Intellisense puts the red squigly line under PageLinks (however in the books project it correctly recognizes it). PageLinks is defined in the same project as follows (there are 3 projects in this solution):

using System;
using System.Text;
using System.Web.Mvc;
using SportsStore.WebUI.Models;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SportsStore.WebUI.HtmlHelpers
{
   public static class PagingHelpers
   {
       public static MvcHtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, Func<int, string> pageUrl)
       {
           StringBuilder result = new StringBuilder();

           for (int i = 1; i <= pagingInfo.TotalPages; i++)
           {
               TagBuilder tag = new TagBuilder("a");
               tag.MergeAttribute("href", pageUrl(i));
               tag.InnerHtml = i.ToString();

               if (i == pagingInfo.CurrentPage)
               {
                   tag.AddCssClass("selected");
                   tag.AddCssClass("btn-primary");
               }
               tag.AddCssClass("btn btn-default");
               result.Append(tag.ToString());
           }

        return MvcHtmlString.Create(result.ToString());
        }
    }
}

For whatever reason it keeps telling me it cannot find the sportsstore namespace. I am so stuck here. I have actually compiled the completed project from the book and gone through to check and see if I can find any differences, no luck so far. I literally checked every reference and compared both web.config files (the main one and the one for the view). Even if I put a @using directive in the view it still doesn't find it. I've had a lot of problems compiling this project actually. Earlier I had a bunch of issues with ninject that required me to edit the web.config file.

If anyone would like a .zip of my entire solution I'd be happy to upload it somewhere (its about 24mb).

Any help appreciated!!

Thanks, Tom

Edit:

Here is the appropriate section in the web.config file for the view:

  <namespaces>
    <add namespace="System.Web.Mvc" />
    <add namespace="System.Web.Mvc.Ajax" />
    <add namespace="System.Web.Mvc.Html" />
    <add namespace="System.Web.Routing" />
    <add namespace="SportsStore.WebUI" />
    <add namespace="SportStore.WebUI.HtmlHelpers"/>

  </namespaces>
like image 497
user3298634 Avatar asked Feb 11 '14 19:02

user3298634


1 Answers

You've misspelled the SportsStore namespace in the last entry. You're missing an 's' before Store.

like image 137
LukeP Avatar answered Nov 14 '22 22:11

LukeP