programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Friday, November 14, 2014

ASP.NET MVC :Add Controllers and Action Methods

Add Controllers and Action Methods in ASP.NET MVC Applications:

ASP.NET MVC Controllers:

  • Controllers Folder contains the controller classes
  • MVC Controller is a simply class file of C# code.
  • A MVC Controller has some Action methods.
  • MVC requires the name of controllers to end with "Controller" word.
  • We create the following files “HomeController.cs” (for the Home page) see the given Image.
ASP.NET MVC :Add Controllers and Action Methods by Parijat

How to Add Controller in MVC Application:

Use the Fallowing steps for Adding a Controller in MVC web project. These are –

Step first:
Open .net IED and create an Empty MVC Application. If you don’t know then view my first post how to start work with MVC project.

Step two:
Right click on Controllers folder and add new controller as like that.

ASP.NET MVC :Add Controllers and Action Methods by parijat

Step three:
Give the name of controller and click on ok button. MVC controller’s C# code :

You can see the MVC controller “HomeController.cs” is create and the code is –

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

namespace MvcApplication1.Controllers
    public class HomeController : Controller
        // GET: /Home/

        public ActionResult Index()
            return View();


Action Method in MVC Controller Class:

In this controller class you have a ActionResult Index() Action Method.
This Method returns to control in a view.

if you want to more about MVC then visit these posts:-

For learning What is View and how to add a view in MVC Application see the next post.

If you want to more than you can add here. related Post:

No comments:

Post a Comment