Skip to main content

Controller in Asp.net Mvc

In this article we will know about Controller in ASP.NET MVC.

The Controller handles incoming URL requests. It is a class which is derived from base class System.Web.Mvc.Controller.

In MVC , every controller class name must end with word "Controller". Let say, controller for home page must be HomeController or contact controller must be ContactController.

Creating an Empty ASP.NET MVC application
Now adding a new controller in MVC application.

In Visual Studio, right click on Controller folder - > select Add - > click on Controller.



After that it will open Add Scaffold dialog as shown



Select "MVC 5 Controller - Empty" and click add button after that it will open Add Controller dialog as shown



In Add Controller Dialog add a name like you want to create student controller then just replace "Default" with "Student" as shown



This will create "StudentController" as shown


Example:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC_BasicTutorials.Controllers
{
    public class StudentController : Controller
    {
        // GET: Student
        public ActionResult Index()
        {
            return View();
        }
    }
}

In the next article we will learn about Action Method





Comments

Popular posts from this blog

CRUD Operation in ASP.NET MVC Using ADO.NET Jquery Ajax

In this article of ASP.NET MVC we will learn about CRUD operation using jquery ajax so let's start. Firstly open visual studio: Go to File => New and Select Project,when you select project then New Project Dialogbox will appear. Select ASP.NET Web Application (.NET Framework) and give a name to your project , as we are building CRUD Operation so our project's name could be CRUD_OPEATION and then select OK. Now you will see a new dialogbox, select Empty Template and MVC folder. After create project you will see a like screen like this: Now go to Models folder and add ADO.NET Entity Data Model and give any name like in my case i give dbEntities and selec OK: After that you will see a dilogbox called Entity Data Model Wizard, select EF Designer from database and select Next: After that a new dilogbox will appear and it will ask a new connection to your sql server, then select New Connection and give server name ( if you want to see your server name then open sql server,it will ...

ASP.NET MVC - Get Started

ASP.NET is a free web framework for building websites and web applications on .NET Framework using HTML, CSS, and JavaScript. These tutorials are designed for beginners and professionals who want to learn ASP.NET MVC 5. In the next article we will learn How to Create First Asp.net MVC application. Click Here To Create First MVC Application

Views in Asp.net Mvc

In this article we will learn about Views in ASP.NET MVC framework, Basically view is the user interface. View display data from model class to viewers. Create New View Open StudentController class then right click inside Index method and Click Add View. After Click Add View , Select "Empty(Without model) " from Add View dialog box then click OK. It will add Index View in View folder. This is how you can add views.