GrandMasterFlush
GrandMasterFlush

Reputation: 6409

Extension method call not working in MVC

I've created an extension method to render a plain HTML link via MVC as in this question:

namespace MyProj
{
    public static class HtmlHelpers
    {
        public static string SectionLink(this HtmlHelper html, string URL, string display)
        {
            return String.Format("<a href=\"{0}\">{1}</a>", URL, display);
        }
    }
}

I've added references in the web.config and the views/web.config can reference it in the page and it Visual Studio doesn't give any errors:

<h1 class="site-title">@HtmlHelpers.SectionLink("https://stackoverflow.com/", "Home")</h1>

Once I run the project I get an error:

Compiler Error Message: CS1501: No overload for method 'SectionLink' takes 2 arguments

I'm stuck on this bit. Visual Studio is happy with the reference but doesn't seem to recognise it's an extension method judging by the error message. What am I doing wrong?

Upvotes: 1

Views: 648

Answers (1)

Eilon
Eilon

Reputation: 25704

Call the method as an extension method:

@Html.SectionLink("abc", "xyz")

Upvotes: 3

Related Questions