1
votes

in my _Layout.cshtml i have this html code

@using PreVenta
<li class="@Html.ActivePage("Home")">
    <a href="@Url.Action("Index", "Home")">
        <i class="fa fa-home"></i>
        <span class="title">Home</span>
        <span class="@Html.SelectedPage("Home")" /> 
    </a>
</li>

and i have a helper to detect the current active page

public static string ActivePage(this HtmlHelper helper, string controller)//, string action)
    {
        string classValue = "";

        string currentController = helper.ViewContext.Controller.ValueProvider.GetValue("controller").RawValue.ToString();
        //string currentAction = helper.ViewContext.Controller.ValueProvider.GetValue("action").RawValue.ToString();

        if (currentController.ToLower() == controller.ToLower()) // && currentAction == action)
        {
            classValue = "start active";
        }

        return classValue;
    }

the main problem is when i try to launch mi webapp, i get this error Compiler Error Message: CS1061: 'System.Web.Mvc.HtmlHelper ' does not contain a definition for 'ActivePage' no extension method 'ActivePage' accepting a first argument of type 'System.Web is not found. Mvc.HtmlHelper '(are you missing a using directive or an assembly reference?).

please some can help me, because i'm very confused. thanks

3
@using PreVenta means you are adding namespace. Is PreVenta valid namespace? - Ashwini Verma
You should show your namespace declaration too - CodingIntrigue
the namespace is namespace PreVenta. the helper file is inside on App_start folder - Francisco Aguayo
can you show complete class? - Ehsan Sajjad

3 Answers

0
votes

that is weird. Can you make sure your helper class look like this?

Helper class

namespace PreVenta
{
    public static class HtmlHelpers
    {
        public static string ActivePage(this HtmlHelper helper, string controller)
        {
            //your code
        }
    }
}

Now you can call helper method like below.

View

@Html.ActivePage("Home")
0
votes

I've found the solution to the problem...

this problems appears when visual studio cannot compile the project succesfully.

to repair this issue, i cleaned up the project, trying to delete the dll's and recompile to release or debug.

Tanks to all, and tanks to VisualTrollStudio ):

-2
votes

You need to add this namespace inside the view in which you want to use this helper

like

@using AppName.SomeNamespace