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.
How to Add Controller in MVC Application:
Use the Fallowing steps for Adding a Controller in asp.net
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 asp.net MVC project.
Step two:
Right click on Controllers folder and add new controller as
like that.
Step three:
Give the name of controller and click on ok button.
Asp.net 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.
Asp.net related Post:
- SQL Server questions for interview
- Find datetime difference in asp.net by C#
- In Asp.net Difference between ""(empty string) and String.Empty
- Asp.net NullReferenceException and how fix it
- Add rows in GridView dynamic with Textbox
- In asp.net by jquery change div text color on mouseover
- Asp.net Watermark Text on uploaded Image
- Create Dynamic Rows in ASP.Net GridView Control with TextBoxes
- Introduction of asp.net mvc model(framework)
- Asp net mvc version, MVC introduction
- Features of ASP.NET MVC Model
- C# Programming language Features
- Validation checkbox control using JavaScript
- jquery disable or Enable submit button after validation
- Enable Disable Submit Button using jQuery
- Check Uncheck all asp.net CheckBox in asp.net using jQuery
- Example of jQuery Validate on Radiobuttonlist in Asp.Net using C#
- Limit Number of Characters in a TextArea using jQuery
- Limitation of Characters in Textbox or TextArea in asp.net using jquery:
- Example jQuery Validate on CheckBoxList using C#
- Check Uncheck all html CheckBox controls using jQuery:
- fill data into Dropdown list by using Jquery
Comments
Post a Comment