I’m trying out ASP.NET MVC, but, after reading a huge tutorial, I’m slightly confused. I understand how Controllers have Actions that URLs are routed to, but how do home pages work? Is the home page its own controller (e.g. “Home”) that has no actions? This sounds correct, but how is it functionality implemented without Actions (no Actions means no methods that call the View Engine)?
In other words, my question is this: how are home pages implemented (in terms of Controllers and Views)? Could you please provide sample code?
“Home” page is nothing more than arbitrary
Actionin a specificControllerwhich returns a certainViewTo set the “Home”, page, or better worded, the default page, you need to change the routing info in the
Global.asax.csfile:Notice the route definition:
This route is a “catch-all” route, meaning it will take any URL and break it down to a specific controller and action and id. If none or one of the routes are defined, it will use the defaults:
This says “If someone visits my application, but didn’t specify the controller or action, I’m going to redirect them to the
NotIndexaction of myNotHomecontroller”. I purposly put “Not” to illustrate that naming conventions of “Default.aspx”, “Index.html” don’t apply to MVC routes.