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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:33:17+00:00 2026-06-12T10:33:17+00:00

I have a controller with an index action. public ActionResult Index(int id = 0)

  • 0

I have a controller with an index action.

public ActionResult Index(int id = 0)
{

    return view();
}

I wish to pass id into the index action, however it doesnt appear to work in the same way as the details action.

e.g. if I want to pass id 4 into the index action, I have to visit url:

http://localhost:8765/ControllerName/?id=4

With the details Action… I can do this.

http://localhost:8765/ControllerName/Details/4

What I want to do with Index is something like…

http://localhost:8765/ControllerName/4

When I visit this url, I get an error:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /fix/1

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

Is this possible? How can I get MVC to automatically treat the index action in the same way as the details one?

Thanks

UPDATE – MY CURRENT ROUTES CONFIG

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
}

UPDATE NEW RouteConfig Class still doesn’t work when I visit localhost:1234/Fix/3

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );

            routes.MapRoute(
            name: "FixIndexWithParam",
            url: "Fix/{id}",
            defaults: new { controller = "Fix", action = "Index", id = UrlParameter.Optional });
    }
}
  • 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-12T10:33:18+00:00Added an answer on June 12, 2026 at 10:33 am

    Update It’s worth pointing out, /ControllerName/Index/4 should work with the default route.

    With the default route there, it expects the second parameter to be the controller name.

    So with the Default Route /ControllerName/4 is being interpereted as ControllerNameController Action 4, which of course does not exist.

    If you add

    routes.MapRoute(
    name: "IndexWithParam",
    url: "{controller}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    

    before the default one it would allow

    /Home/4 to be routed to HomeController action Index with id=4

    I have’t tested this, it may conflict with the default. You may need to specify the controller explicitly in the route, ie:

    routes.MapRoute(
    name: "HomeIndexWithParam",
    url: "Home/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    

    (Obviously, replace Home with whatever controller you’re actually wanting to route to)

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

Sidebar

Related Questions

I have a simple ActionResult in my controller: public ActionResult Index(int productId) { return
I have this controller: public class StandingsController : Controller { public ViewResult Index(int id)
Have Controller: public class MyController : Controller { [HttpGet] public ActionResult MyAction(int iMode, string
I have two actions inside my controller (shoppingCartController) public ActionResult Index() { //some stuff
I have a controller named Content, which has an Index action, which is associated
I'd like to have an Index action for a Users controller that takes an
I have the* Topics * controller and in the view/topics/index.html.erb the link for destroying
lets say I have a controller named Store. There is an index method: public
I have a controller called MetricsController with a single action method: public class MetricsController
I have a controller named BearController. In it I have one index action method

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.