Error following ASP.NET and MVC 5 ... error CS0246: type or namespace not found

So, I follow the examples in the ASP.NET and MVC 5 book. Here is the view that leads to 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 places a red squigly line under PageLinks (however, it recognizes it correctly in a book project). 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 some reason, he keeps telling me that he cannot find the sportsstore namespace. I'm so stuck here. I actually put together the completed project from the book and passed the test to check if I could find any differences until I got lucky. I literally checked every link and compared web.config files (main and one for presentation). Even if I put the @using directive in the view, it still won't find it. In fact, I had a lot of problems compiling this project. I used to have a lot of problems with ninject, which is why I needed to edit the web.config file.

If anyone wanted a .zip of my entire solution, I would be happy to download it somewhere (about 24 MB).

Any help is appreciated !!

Thanks Tom

Edit:

Here is the relevant section in the web.config file for presentation:

  <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> 
+6
source share
2 answers

You made a mistake in the SportsStore namespace in the last post. You miss the "s" in front of the "Store".

+4
source

Try making the namespace available for your browsing through your web configuration.

 <system.web.webPages.razor> <pages pageBaseType="System.Web.Mvc.WebViewPage"> <namespaces> <add namespace="SportsStore.WebUI.HtmlHelpers" /> </namespaces> </pages> </system.web.webPages.razor> 
+1
source

All Articles