Compiler Error Message: CS1061 - MVC4 using VS11

While working on my MVC4 web application using VS11, I ran into the following error. I have an extension method that was to be called from razor page.

Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper<ByteBlocks.ShoppingMall.Models.ProductListViewModel>' does not contain a definition for 'PageLinks' and no extension method 'PageLinks' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<ByteBlocks.ShoppingMall.Models.ProductListViewModel>' could be found (are you missing a using directive or an assembly reference?)

The error itself is self explanatory that application is not able to locate the extension method. This means that the namespace that contained the extension method needs to be included on the page. There are two ways you can accomplish this. First is by adding the namespace in web.config file in page > namesapces section as shown below. This web.config file is the one that you have under Views folder, not the one in root folder of application.

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, 
    System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="ByteBlocks.ShoppingMall.Helpers" />

Second way to include namespace is by adding @using directive at the top of your razor page as shown below.

@using ByteBlocks.ShoppingMall.Helpers




25.0 °C / 77.0 °F

weather conditions Clouds

Monthly Posts

Blog Tags