Monday, 5 September 2011

MVC Convention-Over-Configuration Examples

  1. A simple example of what Convention-Over-Configuration means is:

View files are often associated with an Action method(s) by means of a Naming Convention as opposed to being explicitly configured.

If the framework is requested to find the default view for an action called Index on a controller called HomeController, (if you don't specify a View name in the Action method) it will check the following four locations:

  1. ~/Views/Home/Index.aspx
  2. ~/Views/Home/Index.ascx
  3. ~/Views/Shared/Index.aspx
  4. ~/Views/Shared/Index.ascx
Unlike in traditional ASP.NET Web Forms, PHP, and many older web development platforms, URLs in ASP.NET MVC don't correspond to files on the server's hard disk—instead, they're mapped through a routing configuration onto a controller and action method. Each action method automatically has its own URL; you don't need to create a separate page or class for each URL.

    No comments:

    Post a Comment