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): 43498/ 61

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

User Comments

Title: ASP .Net Developer   
Name: ASP .Net Developer
Date: 2010-05-21 7:26:52 AM
Comment:
Hi
Building a Blog engine throw asp .net is cool.
thanks for this.






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


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-19 4:43:59 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search