ASP.NET MVC > Basics

Create new controller in ASP.NET MVC

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.

 Views: 19679 | Post Order: 6



Write for us






Hosting Recommendations