Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:30:10+00:00 2026-06-13T08:30:10+00:00

So, for some hours now, I have been trying to do something that I

  • 0

So, for some hours now, I have been trying to do something that I thought – and still think – should be trivial. Basically, I created a Html helper that I needed to use to apply some CSS attribute to the selected menu of an ASP.NET MVC 3 Application. Here is my Html helper:

namespace MVCUI.Extensibility
{
    public static class HtmlHelpers
    {
        public static MvcHtmlString MenuLink(
            this HtmlHelper helper, 
            string text, 
            string action, 
            string controller, 
            string selectedCssClass, 
            object routeValues, 
            object htmlAttributes)
        {
            var attributes = new RouteValueDictionary(htmlAttributes);

            if (!String.IsNullOrWhiteSpace(selectedCssClass))
            {
                var contextController = helper.ViewContext.RouteData.Values["controller"] as String ?? "Home";
                var contextAction = helper.ViewContext.RouteData.Values["action"] as String ?? "Index";

                if (String.Compare(
                    String.Format("{0}/{1}", controller, action), 
                    String.Format("{0}/{1}", contextController, contextAction), true) == 0)
                {
                    var cssValue = String.Empty;
                    if (attributes.ContainsKey("class"))
                        cssValue = attributes["class"] as String ?? String.Empty;
                    cssValue = cssValue.Trim();
                    if (cssValue.Length > 0)
                        cssValue = cssValue += (" " + selectedCssClass);
                    else
                        cssValue = selectedCssClass;
                    attributes["class"] = cssValue;
                }
            }

            return helper.ActionLink(text, action, controller, new RouteValueDictionary(routeValues), attributes);
        }
    }
}

Here is how I am using it from a _Layout.cshtml file:

@Html.MenuLink("Posts", "Posts", "Post", "selected", new { }, new { })

For some really odd reason, I keep getting the error:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: ‘System.Web.Mvc.HtmlHelper’ does not contain a definition for ‘MenuLink’ and no extension method ‘MenuLink’ accepting a first argument of type ‘System.Web.Mvc.HtmlHelper’ could be found (are you missing a using directive or an assembly reference?)

Here is what I have tried:

  1. Added <add namespace="MVCUI.Extensibility" /> to <system.web.webPages.razor>/<pages>/<namespaces> section of the Web.config file at the root of the Views folder.
  2. Added @using MVCUI.Extensibility; at the top of the _Layout.cshtml file.
  3. Tried all combinations of (1) and (2) above.
  4. Tried the syntax: @{ Html.MenuLink("Posts", "Posts", "Post", "selected", new { }, new { }); }
  5. Googled, alot! All materials and resources, including our very own stackoverflow, seem to suggest that am doing the right thing.
  6. Even tried setting [assembly: ComVisible(true)] in AssemblyInfo.cs. Well, just in case! 😉

Disclaimer: This is the first time I am trying out a html helper in an ASP.NET MVC 3 application.
Where could I be going wrong? Thanks people.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:30:11+00:00Added an answer on June 13, 2026 at 8:30 am

    Like someone pointed out in the comments, there was something different about my setup. In my solution, I had changed the Output path for my projects – including the MVC project – from the default bin\ to something like ..\Library\Build\. No crime there since that setup has worked fine so far.

    But, that is what got me into trouble. After I restored the default output path and rebuilt my project the Html helper worked. It continued to work even after I restored back my preferred output path – obviously because the dll in the bin folder got updated.

    This would mean that the statement @using MVCUI.Extensibility; in my .cshtml file and <add namespace="MVCUI.Extensibility" /> in the Web.config were referencing an old outdated dll in the bin folder that didn’t have the HtmlHelper defined. This bothers still. How would I have them reference the dll in my desired output path?

    Anyway, I just thought I should post about the experience and the lessons just in case other people find themselves in similar trouble. Thanks people.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been spending the last hours trying to figure this out and now
I've been stuck with this for hours now. I think it's time for some
I have been looking into this for some hours now and can't figure it
I've been fighting this problem for many hours now and could really use some
I have been trying for about an hour now to find an elegant solution
I've been trying to figure this out for a few hours now. In order
I've been trying to get through this for a couple of hours now and
I have been searching for several hours now and have so far had no
I've been trying to get this code to work for a few hours now
I've been looking around the net for a good few hours now, trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.