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 8581609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:05:40+00:00 2026-06-11T21:05:40+00:00

I’m using MvcContrib’s strongly typed RedirectToAction() to redirect from one controller action to another,

  • 0

I’m using MvcContrib’s strongly typed RedirectToAction() to redirect from one controller action to another, while avoiding magic strings in my application flow, like so:

this.RedirectToAction<FooController>(c => c.Bar());

which in turn redirects to

/foo/bar/    

… but now I’d like to be able to redirect to an URL with an anchor/hashtag at the end, and scroll the window to the <a name="yarrr" /> tag, like so:

/foo/bar/#yarrr  

I could put the hashtag in TempData[], write it in a javascript variable and have the window scroll via javascript – but I’d rather follow convention and have the hashtag as the end of my URL.

Any ideas or home made solutions for this?
MvcContrib doesn’t seem to support it.

  • 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-11T21:05:42+00:00Added an answer on June 11, 2026 at 9:05 pm

    I am not aware of the existence of such an ActionLink overload in MvcContrib but writing one would be trivial:

    using System;
    using System.Linq.Expressions;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;
    using System.Web.Routing;
    
    public static class HtmlExtensions
    {
        public static IHtmlString ActionLink<TController>(
            this HtmlHelper html,
            Expression<Action<TController>> action,
            string linkText,
            object htmlAttributes,
            string fragment
        ) where TController : Controller
        {
            var routeValues = Microsoft.Web.Mvc.Internal.ExpressionHelper
                .GetRouteValuesFromExpression(action);
            return html.RouteLink(
                linkText: linkText,
                routeName: null,
                protocol: null,
                hostName: null,
                fragment: fragment,
                routeValues: routeValues,
                htmlAttributes: new RouteValueDictionary(htmlAttributes)
            );
        }
    }
    

    and then in your view:

    @(Html.ActionLink<FooController>(c => c.Bar(), "click me", null, "yarrr"))
    

    UPDATE:

    Apparently I misunderstood your question as you were looking for a RedirectToAction method in the controller, not inside the view. My answer is the same as previously: I am not aware of the existence of such an RedirectToAction overload in MvcContrib but writing one would be trivial:

    using System;
    using System.Linq.Expressions;
    using System.Web.Mvc;
    
    public static class HtmlExtensions
    {
        public static RedirectResult RedirectToAction<TController>(
            this Controller controller,
            Expression<Action<TController>> action,
            string fragment
        ) where TController : Controller
        {
            var routeValues = Microsoft.Web.Mvc.Internal.ExpressionHelper
                .GetRouteValuesFromExpression(action);
            var urlHelper = new UrlHelper(controller.ControllerContext.RequestContext);
            return new RedirectResult(
                UrlHelper.GenerateUrl(
                    routeName: null,
                    actionName: null,
                    controllerName: null,
                    protocol: null,
                    hostName: null,
                    fragment: fragment,
                    routeValues: routeValues,
                    routeCollection: urlHelper.RouteCollection,
                    requestContext: controller.ControllerContext.RequestContext,
                    includeImplicitMvcValues: true
                )
            );
        }
    }
    

    and then inside your controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return this.RedirectToAction<FooController>(c => c.Bar(), "yarrr");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.