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>
You've misspelled the SportsStore namespace in the last entry. You're missing an 's' before Store.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With