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

  • SEARCH
  • Home
  • 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 9081667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:22:11+00:00 2026-06-16T20:22:11+00:00

I created an HtmlHelper extension call ActionButton which will spit out a jQuery button

  • 0

I created an HtmlHelper extension call ActionButton which will spit out a jQuery button that will call an action rather than using ActionLink. However, I receive an exception from within my extension method on the following line (it’s just a sample of code that will raise the exception I was seeing):

    MvcHtmlString str = helper.Action(actionName, controllerName, routeValues);

Here’s the full method but using UrlHelper to create the Action URL (which works for me). I also have using System.Web.Mvc and using System.Web.Mvc.Html.

    public static HtmlString ActionButton(this HtmlHelper helper, string linkText, string actionName, string controllerName, object routeValues)
    {
        TagBuilder tag = new TagBuilder("a");
        UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
        tag.MergeAttribute("href", urlHelper.Action(actionName, controllerName, routeValues));

        // the next line causes the exception, not really being used other than to 
        // raise the exception and illustrate the call I was making
        MvcHtmlString str = helper.Action(actionName, controllerName, routeValues);

        tag.MergeAttribute("rel", "external");
        tag.MergeAttribute("data-role", "button");
        tag.MergeAttribute("data-mini", "true");
        tag.MergeAttribute("data-inline", "true");
        tag.MergeAttribute("data-icon", "arrow-r");
        tag.MergeAttribute("data-iconpos", "right");
        tag.MergeAttribute("data-theme", "b");

        tag.SetInnerText(linkText);
        HtmlString html = new HtmlString(tag.ToString(TagRenderMode.Normal));
        return html;
    }

I would like to know why calling helper.Action(...) raises an exception.

Thanks!

  • 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-16T20:22:12+00:00Added an answer on June 16, 2026 at 8:22 pm

    HtmlHelper.Action() will call the action method you pass it immediately, and return its results.
    That’s not what you want.

    You want UrlHelper.Action(), which returns a URL to the action.

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

Sidebar

Related Questions

I have created an HtmlHelper Extension method which returns an encoded string, I have
I have the following HTMLHelper extension to create a submit button that would work
I created an extension method for the HtmlHelper which works very well. Now I
I created an HtmlHelper method called DisplayListBoxFor that will need display a textual representation
I've created a extension method of Jquery datepicker, below are the source code. public
UPDATED I am trying to create an HtmlHelper Extension that has the ability to
I'm trying to create an HtmlHelper extension that outputs some HTML to the view.
I have created my own extension as: public static MvcHtmlString hSearch(this HtmlHelper helper, string
I created some theme HtmlHelper extensions for that grab the .css and .js files
I want to create an extension method for HtmlHelper that allows me to create

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.