Building a Simple Blog Engine with ASP.NET MVC and LINQ - Part 2
page 3 of 7
by Keyvan Nayyeri
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28226/ 277

The Anatomy of a Controller Class

A controller class is a class just like other classes. It is not necessary to derive this class from a special class or implement an interface for it, but it is recommended to derive a controller class from System.Web.MVC.Controller base class for ease of development and getting the benefits of this base class in your development.

Controller class provides some tools that can assist you on developing your ASP.NET MVC applications and I do not think any developer wants to avoid using it. Controller class is applied to all project and file item templates in Visual Studio and whenever you create a new MVC controller class in Visual Studio this class appears in your code.

You can add a new MVC controller class file in the Add New Item dialog as is shown in Figure 1.

Figure 1

Listing 1 shows the default code for a controller class that I named SampleController.

Listing 1

using System;
using System.Web;
using System.Web.Mvc;
 
namespace KBlog.Controllers
{
    public class SampleController : Controller
    {
        [ControllerAction]
        public void Index()
        {
            //Add action logic here
        }
    }
}

As you see, there is a reference to System.Web.Mvc namespace which comes to your machine after installing the ASP.NET 3.5 extensions and the class is also derived from the Controller base class.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 3 and 5 and type the answer here:

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2010 ASPAlliance.com  |  Page Processed at 3/21/2010 8:15:23 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search