Error in HtmlHelper function in a view. It works fine in a .cs file.

I'm following a tutorial in Pro ASP.NET MVC 5.  I get this error:


Severity      Error

Code            CS1061      
                                                                              
Description      'HtmlHelper<ProductsListViewModel>' does not contain a definition for 'PageLinks'
            and no extension method 'PageLinks' accepting a first argument of type
            'HtmlHelper<ProductsListViewModel>' could be found
            (are you missing a using directive or an assembly reference?)      
                              
Project      File      SportsStore.WebUI      

Line            SportsStore\SportsStore.WebUI\Views\Product\List.cshtml      15

Suppression State      Active

The code is attached.

The error points to line 15 of LIst.cshtml.   It seems to say that I'm passing a ProductsListViewModel as the first argument, but I'm passing a PagingInfo.  I successfully call this method in UnitTest.cs

Why does it think a PagingInfo is it's parent, ProductsListViewModel?
SportsStorePageLinksError.txt
Barry SweezeySoftware EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Snarf0001Commented:
The view doesn't have native visibility of the PageHelpers class you created.
Go to the "sub" web.config under the Views folder.  You should have several default namespaces already included in there, add another one to include the SportsStore.WebUI.HtmlHelpers namespace.
Then the view should be able to pick up the extension method.
0
Barry SweezeySoftware EngineerAuthor Commented:
Thanks for your reply.  I added the line to SportsStore\SportsStore.WebUI\Views\web.config, but the error is the same.

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <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="SportsStore.WebUI.HtmlHelpers" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>
0
Snarf0001Commented:
Okay, try one other thing for me.
The calling code you posted is:

@Html.PageLinks(Model.PagingInfo, i => i);

Open in new window


That could conceivably be causing the problem, because it would be expecting a Func<int, int> instead of the Func<int, string> you have declared.
So might be failing to find a proper overload.

Try changing to
@Html.PageLinks(Model.PagingInfo, i => i.ToString());

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Barry SweezeySoftware EngineerAuthor Commented:
Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.