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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:22:53+00:00 2026-05-12T18:22:53+00:00

Could someone explain how routes are associated with controllers in MVC 2? Currently, I

  • 0

Could someone explain how routes are associated with controllers in MVC 2? Currently, I have a controller in /Controllers/HomeController.cs and a view /Home/Index.aspx.

My route registration method looks like this:

 public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
            routes.MapRoute(
               "Default",
                // Route name
               "{controller}/{action}/{id}",
                // URL with parameters
               new { controller = "Home", action = "Index", id = "" }
                // Parameter defaults
              );
        }

If I request the URL: http://localhost/Home/Index, then the request is correctly handled by HomeController.Index().

However, for the life of me, I can’t figure out how the url /Home/Index gets pointed to HomeController. The view aspx doesn’t, as far as I can tell, reference HomeController, HomeController doesn’t reference the view, and the route table doesn’t explicitly mention HomeController. How is this magically happening? Surely I’m missing something obvious.

then

  • 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-12T18:22:54+00:00Added an answer on May 12, 2026 at 6:22 pm

    The default views engine that comes with ASP.NET MVC works on the following conventions:

    You have a folder structure like this:

    - Controllers\
    |-  HomeController.cs
    - Views\
    |- Home\
    |-- Index.aspx
    |- Shared\
    

    When a request comes in, and matches a route defined in the RegisterRoutes method (see things like URL routing for more on that), then the matching controller is called:

    routes.MapRoute(
      "Default", // Route name, allows you to call this route elsewhere
      "{controller}/{action}/{id}", // URL with parameters
      new { controller = "Home", action = "Index", id = "" } // Parameter defaults
      );
    

    In the default route, you are also specifying a default controller (without the "Controller" suffix) – the routing engine will automatically add Controller onto the controller name for you – and a default action.

    In your controller, you call the simple method:

    public ActionResult Index(){
      return View();
    }
    

    The default view engine then looks for an aspx file called Index (the same as the action) in a folder called "Home" (the same as the controller) in the "Views" folder (convention).

    If it doesn’t find one in there, it will also look for an index page in the Shared folder.

    From the ASP.NET MVC Nerd Dinner sample chapter

    ASP.NET MVC applications by default use a convention-based directory naming structure when resolving view templates. This allows developers to avoid having to fully-qualify a location path when referencing views from within a Controller class. By default ASP.NET MVC will look for the view template file within the \Views\[ControllerName]\ directory underneath the application.

    The \Views\Shared subdirectory provides a way to store view templates that are re-used across multiple controllers within the application. When ASP.NET MVC attempts to resolve a view template, it will first check within the \Views\[Controller] specific directory, and if it can’t find the view template there it will look within the \Views\Shared directory.

    When it comes to naming individual view templates, the recommended guidance is to have the view template share the same name as the action method that caused it to render. For example, above our "Index" action method is using the "Index" view to render the view result, and the "Details" action method is using the "Details" view to render its results. This makes it easy to quickly see which template is associated with each action.

    Developers do not need to explicitly specify the view template name when the view template has the same name as the action method being invoked on the controller. We can instead just pass the model object to the View() helper method (without specifying the view name), and ASP.NET MVC will automatically infer that we want to use the \Views\[ControllerName]\[ActionName] view template on disk to render it.


    Edit to add:

    Some example routes I’ve set up, that explicitly set the controller are:

    routes.MapRoute(
      "PhotoDetailsSlug",
      "Albums/{albumId}/{photoId}/{slug}",
      new {controller = "Albums", action = "PhotoDetails"},
      new {albumId = @"\d{1,4}", photoId = @"\d{1,8}"}
      );
    

    Here I’m explicitly stating that I’m using the Albums controller, and the PhotoDetails action on that, and passing in the various ids, etc to the that action.

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

Sidebar

Related Questions

could someone explain the code in catch_exceptions? i have difficulties to understand. thanks class
Could someone explain to me why it is considered inapropriate to have a try-catch
Could someone explain me why do I have the following result with the following
Could someone explain this for me? I have standard relations in my MSSQL DB:
Could someone explain to me in simple terms the easiest way to change the
Could someone explain? I understand the basic concepts behind them but I often see
Could someone explain why this works in C#.NET 2.0: Nullable<DateTime> foo; if (true) foo
Could someone explain why both tests using the latest versions of Moq and Rhino.Mocks
Could someone explain what I am doing wrong with my classes that my JTabbedPane
Could someone explain to me how can I run my py2exe program, a console

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.