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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:01:05+00:00 2026-05-16T09:01:05+00:00

Update: As someone pointed out I was missing an s in my Route registration.

  • 0

Update:

As someone pointed out I was missing an s in my Route registration. Now I have a secondary problem.

This is how I want it to work:

http://localhost/products/ –> ProductsController.Index()

http://localhost/products/3/apples –> ProductsController.Details(int? id, string productName)

This is what currently happens:

http://localhost/products goes to my Details action.

How do I set up the routes for this?

I set up the following routes in my Global.asx file:

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

    routes.MapRoute(
        "ViewProduct",
        "products/{id}/{productName}",
        new { controller = "Products", action = "Details", id = 0, productName = "" } // Parameter defaults
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );
}

I have the following controller:

public class ProductsController : Controller
{
    //
    // GET: /Products/

    public ActionResult Index()
    {
        IList<Product> products = new List<Product>
        {
            new Product { Id = 57349, ProductName = "Apple" },
            new Product { Id = 57350, ProductName = "Banana" }
        };

        return View(products);
    }

    public ActionResult Details(int? id, string productName)
    {
        Product p = new Product { Id = id.Value, ProductName = productName };

        return View(p);
    }
}
  • 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-16T09:01:06+00:00Added an answer on May 16, 2026 at 9:01 am

    Because you have defined default values for id and productName the routing engine just fills those in for you when they are missing, so your request to /products is getting those defaults inserted and going to the details action.

    Take out: id = 0, productName = "" and you’ll get the expected behavior.

    edit

    Consider having an {action} parameter in there. Since you have a default action and no way to override it you may have everything routed to details anyway.

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

Sidebar

Related Questions

Update: This does work, I was being stupid :( i have the following extension
Could someone tell me why this code does not update the data response? It's
I have been up for quite awhile trying to figure this out. On this
UPDATE: Runs like a charm now. With the help of Alex Klimashevsky who pointed
Im trying to update someone else's Rails app. Right now, an HTML table displays
I am trying to update some hibernate code that was written by someone else
I updated my User class, and now whenever someone that had the old version
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
Update: I'm not looking for someone to come up with a schema for me.
So here I believe I have a small buffer overflow problem I found when

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.