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

The Archive Base Latest Questions

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

I am using MVC 4.0 and I am trying to add a route for

  • 0

I am using MVC 4.0 and I am trying to add a route for each controller.

Well, my first controller is called CustomersController. The route that I’ve
added is:

    routes.MapRoute(
        name: "Customer",
        url: "{controller}/{action}/{IdCustomer}",
        defaults: new { controller = "Customers", action = "Index", IdCustomer = UrlParameter.Optional }
    );

When I am running the application, I get the following links in the Index page(List):

http://localhost:6838/Customers/Create/5
http://localhost:6838/Customers/Edit/5
http://localhost:6838/Customers/Details/5
http://localhost:6838/Customers/Delete/5

Ok, great! It’s what I am looking for, but, now start my problem. I added another
controller, called ItemsController (with the same actions – Create/Edit/Details/Delete) then I tried to add the same route:

    routes.MapRoute(
        name: "Item",
        url: "{controller}/{action}/{IdItem}",
        defaults: new { controller = "Items", action = "Index", IdItem = UrlParameter.Optional }
    );

But now the result is different… I am getting the following links:

    http://localhost:6838/Items/Create?IdItem=1
    http://localhost:6838/Items/Edit?IdItem=1
    http://localhost:6838/Items/Detail?IdItem=1
    http://localhost:6838/Items/Delete?IdItem=1

WHY.. WHY :'( it isn’t working? Why it’s working only for the first route and not
for the new one just added?!

Best regards,
Dan

  • 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-11T04:06:01+00:00Added an answer on June 11, 2026 at 4:06 am

    To give a synopsis of my answer, your routes are too vague. You need to be more specific to get a better result (especially if you’re not using the route by name). I would go for something like the following:

    routes.MapRoute(
        name: "Customers",
        url: "Customers",
        defaults: new { controller = "Customers", action = "Index" }
    );
    routes.MapRoute(
        name: "CustomerDetails",
        url: "Customer/{IdCustomer}",
        defaults: new { controller = "Customers", action = "Details", IdItem = UrlParameter.Optional }
    );
    routes.MapRoute(
        name: "CustomerEdit",
        url: "Customer/{IdCustomer}",
        defaults: new { controller = "Customers", action = "Edit", IdItem = UrlParameter.Optional }
    );
    /* and so on (then move on to Items) */
    

    Now you can reference them by name and also eliminate a lot of the rudimentary information you normally provide (like action and controller details). It also makes updating a link easier down the road as the route is named and not an explicit controller/action.

    @Html.RouteLink("Edit Customer", "CustomerEdit", new { IdCustomer = model.Id });
    

    You can now make this in a different area or have another controller handle it later by changing your route defined and all your RouteLinks could remain the same.

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

Sidebar

Related Questions

I'm new to using MVC and I'm trying to make a model that uses
I'm using spring MVC and spring security. I have annotation-driven controller and trying to
I'm trying to add dynamic content to my mvc application. I'm using Steven Sanderson
I am using ASP.NET MVC 3.0 and KnockoutJS . I was trying to add
I am using ASP.NET 4 and MVC and trying to add code to handle
I have an ASP.NET site that is not currently using MVC but I'm trying
I am using TinyMCE with MVC 3 razor engine. I am trying to add
I'm trying to add a Metadata partial class to an existing MVC using EF
I'm trying to add logging through AOP in an ASP.NET MVC application using: Enterprise
Using Asp.Net MVC 3 (Razor). I'm trying to add the blockUI plug in to

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.