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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:27:07+00:00 2026-06-17T06:27:07+00:00

So I have this controller action: public ActionResult Categories(int typecode) { // code removed

  • 0

So I have this controller action:

public ActionResult Categories(int typecode)
{
  // code removed
}

this route:

routes.MapRoute(null,
  "{controller}/{action}/{typecode}",
  new { controller = "Search", action = "Categories", }
);

and this link to call the route:

@Html.ActionLink("Ga", "Categories", "Search", new { typecode = 16860 }, null)

if I use this, my URL is: http://localhost:50033/Search/Categories?typecode=16860
but if I change all occurences of typecode to id, it works and I get this URL: http://localhost:50033/Search/Categories/16860

So with typecode my route doesn’t work and with id it does. What am I doing wrong? Thanks!

EDIT:

I think I wasn’t clear enough, but in my Global.asax.cs file I have this:

public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute("TypeCode",
    "Search/Categories/{typecode}",
    new { controller = "Search", action = "Categories" }
  );
}

So that’s only ONE route, than in my SearchController I have this Categories action:

public ActionResult Categories(int typecode)
{
  // Irrelevant code removed
}

So the parameter is exactly the same as the route parameter, then I have this link:

@Html.ActionLink("Ga", "Categories", "Search", new { typecode = 16860 }, null)

Also using exactly the route parameter, but still the generated link is: http://localhost:50033/Search/Categories?typecode=16860 so that’s not what I want.

Now, when i replace all typecode occurences, like this:

public static void RegisterRoutes(RouteCollection routes)
{
  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

  routes.MapRoute("TypeCode",
    "Search/Categories/{id}",
    new { controller = "Search", action = "Categories" }
  );
}

public ActionResult Categories(int id)
{
  // irrelevant code removed
}

@Html.ActionLink("Ga", "Categories", "Search", new { id = 16860 }, null)

It works! so I replaced everything, there are no more routes, I just replaced the 3 typecode occurences with id.

Why is this? Can anyone help me with this please? Thanks in advance!

  • 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-17T06:27:08+00:00Added an answer on June 17, 2026 at 6:27 am

    The problem is solved. I will explain what went wrong for anyone who has the same issue.

    I am using ASP.NET MVC 4 for this project, earlier I created some webshops with MVC 3. What I always did, was putting the routes in the Global.asax.cs file. Now, when I started my project, there was no RegisterRoutes() method, so I created one and put my routes in it. Just now I read this post and it says that MVC 4 registers its routes in App_Data/RouteConfig.cs I checked out that file, and saw the RegisterRoutes() method with one route, the default one with as optional parameter id.

    So that is why it was only working with id as parameter, MVC 4 didn’t even look at my route in Global.asax.cs, and just picked up the only route from App_Data/RouteConfig.cs.

    I did put my route in the App_Data/RouteConfig.cs file and it works! Learned something again, and I’m glad it finally works. Also I want to say thanks to @James for helping me.

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

Sidebar

Related Questions

Inside my controller's action I have the following code: public ActionResult GridAction(string id) {
I have this controller: public class StandingsController : Controller { public ViewResult Index(int id)
I have this Controller : public class ProfileController : Controller { public ActionResult Index(
I have this set of routes: routes.MapRoute( IssueType, issue/{type}, new { controller = Issue,
I have this in my controller public ActionResult Testing() { CustomerContactModel model = new
In my route I have something like this: controller/action/{id} To my knowledge this means
Global.asax route values routes.MapRoute( Default, // Route name {controller}/{action}/{id}, // URL with parameters new
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
I have this custom action filter: public class PermissionChecker: ActionFilterAttribute { private int _permissionId
I have this code in the client side: $.post('<%=Url.Action(Action_Name,Controller_Name)%>', { serverParam: clientParam}, null, null);

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.