Notes on ASP.NET MVC

The Tenets of MVC

  1. Separation of concerns
  2. Convention over configuration
  3. Keep it DRY: Don’t Repeat Yourself
  4. Be helpful, but get out of my way

The MVC URL Pattern

/domain/controller/action-method/id

Controllers in MVC

A Controller must:

  1. Implement the System.Web.Mvc.IController interface. However, typically we will implement the  System.Web.Mvc.Controller abstract class which inherits the ControllerBase class which, in turn, inherit IController.

  2. Have a name ending in “Controller”
  3. Be marked as “public” – not “abstract” – and cannot take generic parameters

Action Method Qualifications

  1. Method must meet requirements to be action method:
    • Must be public – not static or shared
    • Cannot be defined on System.Object or Controller (i.e. ToString() could not be an action method)
    • Cannot be a special method
    • Cannot have a NonAction attribute
  2. Action Invoker uses reflection to find candidates
    • All methods with same action name
    • But method attributes can make this murky with multiple candidates
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s