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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:43:59+00:00 2026-05-17T00:43:59+00:00

The very famous ActionLink : <%: Html.ActionLink(Back to List, Index)%> Now, this link is

  • 0

The very famous ActionLink:

 <%: Html.ActionLink("Back to List", "Index")%>

Now, this link is in my Details view. The Index view is a search page. The URL of that looks like this:

http://localhost:50152/2011-2012/Instelling/Details/76?gemeente=Dendermonde&postcode=92**&gebruikerscode=VVKSO114421&dossiernr=114421%20&organisatie=CLB

As you can see, quite the amount of parameters. Obviously I want to keep all these parameters when I return to the Index page, so I need to add them in the ActionLink.

Now, I’m tired of doing that manually, it’s ok for 1, but not for 6. This should go a lot easier.

Question: How do I return All parameters of the current URL into the ActionLink as optional RouteValues.

I’ve been looking to Request.QueryString. It has to be something with that. I was thinking of writing some static method in Global.asax doing the job but no luck yet. Maybe there is an easy way to do this which I don’t know about?

Edit: This is what I came up with (which works)

In global.asax:

    public static RouteValueDictionary optionalParamters(NameValueCollection c) {
        RouteValueDictionary r = new RouteValueDictionary();
        foreach (string s in c.AllKeys) {
            r.Add(s, c[s]);
        }
        return r;
    }

Details.aspx:

    <%: Html.ActionLink("Back to List", "Index", MVC2_NASTEST.MvcApplication.optionalParamters(Request.QueryString))%>

Where do I best put this code? not in Global.asax I guess…

Edit 2:

using System;
using System.Web.Mvc;

namespace MVC2_NASTEST.Helpers {
    public static class ActionLinkwParamsExtensions {
        public static MvcHtmlString CustomLink(this HtmlHelper helper, string linktext) {
            //here u can use helper to get View context and then routvalue dictionary
            var routevals = helper.ViewContext.RouteData.Values;
            //here u can do whatever u want with route values
            return null;
        }

    }
}


<%@ Import Namespace="MVC2_NASTEST.Helpers" %>
...
<%: Html.ActionLinkwParams("Index") %>
  • 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-05-17T00:44:00+00:00Added an answer on May 17, 2026 at 12:44 am

    This is how I finally fixed it, and i’m rather proud because it’s working very well and very DRY.

    The call in the View:

        <%: Html.ActionLinkwParams("Back to List", "Index")%>
    

    but with the overloads it can be anything which a normal ActionLink takes.

    The Helper:

    The helper takes all parameters from the url which are not in the route.
    For example: this url:

    http://localhost:50152/2011-2012/myController/Details/77?postalCode=9***&org=CLB
    

    So it will take the postalCode and the Org and place it in the new ActionLink.
    With the overload, additional parameters can be added, and parameters from the existing url can be removed.

    using System;
    using System.Web.Mvc;
    using System.Web.Routing;
    using System.Collections.Specialized;
    using System.Collections.Generic;
    
    namespace MVC2_NASTEST.Helpers {
        public static class ActionLinkwParamsExtensions {
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action, string controller, object extraRVs, object htmlAttributes) {
    
                NameValueCollection c = helper.ViewContext.RequestContext.HttpContext.Request.QueryString;
    
                RouteValueDictionary r = new RouteValueDictionary();
                foreach (string s in c.AllKeys) {
                    r.Add(s, c[s]);
                }
    
                RouteValueDictionary htmlAtts = new RouteValueDictionary(htmlAttributes);
    
                RouteValueDictionary extra = new RouteValueDictionary(extraRVs);
    
                RouteValueDictionary m = Merge(r, extra);
    
                return System.Web.Mvc.Html.LinkExtensions.ActionLink(helper, linktext, action, controller, m, htmlAtts);
            }
    
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action) {
                return ActionLinkwParams(helper, linktext, action, null, null, null);
            }
    
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action, string controller) {
                return ActionLinkwParams(helper, linktext, action, controller, null, null);
            }
    
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action, object extraRVs) {
                return ActionLinkwParams(helper, linktext, action, null, extraRVs, null);
            }
    
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action, string controller, object extraRVs) {
                return ActionLinkwParams(helper, linktext, action, controller, extraRVs, null);
            }
    
            public static MvcHtmlString ActionLinkwParams(this HtmlHelper helper, string linktext, string action, object extraRVs, object htmlAttributes) {
                return ActionLinkwParams(helper, linktext, action, null, extraRVs, htmlAttributes);
            }
    
    
    
    
            static RouteValueDictionary Merge(this RouteValueDictionary original, RouteValueDictionary @new) {
    
                // Create a new dictionary containing implicit and auto-generated values
                RouteValueDictionary merged = new RouteValueDictionary(original);
    
                foreach (var f in @new) {
                    if (merged.ContainsKey(f.Key)) {
                        merged[f.Key] = f.Value;
                    } else {
                        merged.Add(f.Key, f.Value);
                    }
                }
    
                return merged;
    
            }
        }
    
    }
    

    In the View using overloads:

     <%: Html.ActionLinkwParams("Back to List", "Index","myController", new {testValue = "This is a test", postalCode=String.Empty}, new{ @class="test"})%>
    

    in the URL I have the paramters postalCode with some value. my code takes All of them in the URL, by setting it to string.Empty, I remove this parameter from the list.

    Comments or ideas welcome on optimizing it.

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

Sidebar

Related Questions

Very newbie question. For instance, is this okay? <a href=allaboutpeanuts.html>Peanuts<img src=peanut.jpg> </a> I tried
Very often when working on an ASP.NET web site, the options View Code and
Very odd problem as this is working perfectly on our old Classic ASP site.
Very similar to this question , except for Java. What is the recommended way
Recently I have read about hash-tables in a very famous book Introduction to Algorithms
I have what I think is a very simple problem (famous last words)... I
Very likely I'm going about this in the wrong way entirely. I'm completely new
I have run into what seems to be a very famous problem: My updatepanel
Very simply put: I have a class that consists mostly of static public members,
Very simply put, I have the following code snippet: FILE* test = fopen(C:\\core.u, w);

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.