Wednesday, 5 August 2015

ASP.NET MVC - Create new controller How to create a new controller in asp.net mvc?

To create a new controller, right click the Controllers folder and select Add > Controller



Select the type of controller you want to create and click Add button.


Write the controller name (notice the selected characters, you need to replace only selected characters from the controller name and click Add.



This will create a DefaultController whose code would look similar to this 
/Controllers/DefaultController.cs 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication4.Controllers
{
    public class DefaultController : Controller
    {
        // GET: Default  
        public ActionResult Index()
        {
            return View();
        }
    }
}

Notice the ~/Views folder of the project, a corresponding Default folder would also get created when the controller gets created.


What do you think?
I hope you will enjoy create Controller while programming with Asp.Net MVC. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

No comments:

Post a Comment