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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:58:20+00:00 2026-05-20T03:58:20+00:00

Global.asax route values routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with parameters new

  • 0

Global.asax route values

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional, filterDate = DateTime.Now.AddDays(-1), filterLevel = "INFO" } // Parameter defaults
        );

Here’s my actionlink

        @Html.ActionLink(item.MachineName, "Machine", new { id = item.MachineName, filterLevel = "hello" }, null)

When the filterlevel is specified in the actionlink, it generates a url like this:

http://localhost:1781/LoggingDashboard/log/level/VERBOSE

Which is the same page as I am currently on. If I change the actionlink to use a property other than one that has a default value in the route table (yes, if I use filterDate it messes up too), it generates a link like this:

@Html.ActionLink(item.MachineName, "Machine", new { id = item.MachineName, foo = "bar" }, null)

http://localhost:1781/LoggingDashboard/log/Machine/C0UPSMON1?foo=bar

Is this behavior correct? Should I not be able to override the defaults set up in the route table? I have confirmed that if I remove the filterLevel default from the route table this works as I expect:

http://localhost:1781/LoggingDashboard/log/Machine/C0UPSMON1?filterLevel=VERBOSE

—EDIT—
sorry, here is the action

        public ActionResult Machine(string id, DateTime filterDate, string filterLevel)
        {
...
            var model = new LogListViewModel { LogEntries = logEntries };
            return View(model);
        }

For the bounty I want to know how to override the “default” values that are specified in the routes from global.asax. i.e. I want to be able to override filterLevel and filterDate.

  • 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-20T03:58:21+00:00Added an answer on May 20, 2026 at 3:58 am

    SLaks already said what is probably the best way to handle this problem. I don’t know if this will work, but, what happens if you put this above the existing route (so there would be two in your global.asax now)?

            routes.MapRoute(
                "Filtered",
                "{controller}/{action}/{id}?filterLevel={filterLevel}&filterDate={filterDate}",
                new
                    {
                        controller = "Home",
                        action = "Index",
                        id = UrlParameter.Optional,
                        filterDate = DateTime.Now.AddDays(-1),
                        filterLevel = "INFO"
                    } 
                );
    

    Also, it just occurred to me that the reason you don’t like SLaks’ solution is that it could be repetitive. Since you only have one route, these parameters probably indicate a global functionality, instead of an action-scoped functionality. You could fix this by adding the values in an action filter on each controller, or your could use a custom route handler to apply this globally. Either of these would allow you to take the filterLevel and filterDate fields out of your route definition and still get the scope you want. Then it should be no problem to pass the parameters in a querystring with Html.ActionLink().

    To do this with the route handler, change your route definition to:

            routes.Add(
                new Route(
                        "{controller}/{action}/{id}", 
                        new RouteValueDictionary(new{ controller = "Home", action = "Index", id = UrlParameter.Optional}), 
                        new CustomRouteHandler()));
    

    Your implementation of the route handler would be something like this:

    public class CustomRouteHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var routeValues =  requestContext.RouteData.Values;
            if(!routeValues.ContainsKey("filterLevel"))
            {
                routeValues.Add("filterLevel","INFO");
            }
            if(!routeValues.ContainsKey("filterDate"))
            {
                routeValues.Add("filterDate", DateTime.Now.AddDays(-1));
            }
            var mvcRouteHandler = new MvcRouteHandler(); 
            return (mvcRouteHandler as IRouteHandler).GetHttpHandler(requestContext);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this route values inside Global.asax routes.MapRoute( Default, // Route name {controller}/{action}/{id}, //
I have two MapRoute in global asax.` routes.MapRoute( AutoGeneratedURLHandler, // Route name {modulepath}/{controller}/{action}/{id}, //
I have the following routes defined in my Global.asax: routes.MapRoute(name: Home, url: , defaults:
i defined two routes in global.asax like below context.MapRoute(HomeRedirect, , new { controller =
I have the following routes defined in my global.asax: routes.MapRoute( Agreements2, // Route name
SOLUTION the route routes.MapRoute( Whatever, // Route name {controller}/{action}/{id}, //{ID} MUST BE USED IN
i want to route Default.aspx to another URL when page starts. my global.asax is
In my mvc4 project, I have the following routing defined in Global.asax: routes.MapHttpRoute( name:
I wrote the code in global.asax contain this oRoutes.MapPageRoute(test-route, home/{cURL}, ~/test.aspx); everything fine, but
How should I define route in my global.asax to be able use nullable parameters

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.