How to add a Controller in ASP.NET MVC

Total Post:135

 1158  View(s)
Rate this:
Hi Everyone,
 Now, i am working on a very popular topic of ASP.NET i.e. ASP.NET MVC framework. So, i want that can anyone  explain how to adding a controller in a my  mvc application.

Thank you.
  1. Post:135

    Re: How to add a Controller in ASP.NET MVC

    MVC stands for model-view-controller.  MVC is a pattern for developing applications that are well architected, testable  and easy to maintain. MVC-based applications contain:

    • Models: Classes that represent the data of the application  and that use validation logic to enforce business rules for that data.
    • Views: Template files that your application uses to dynamically  generate HTML responses.
    • Controllers: Classes that handle incoming browser requests,  retrieve model data, and then specify view templates that return a response  to the browser.

    Let's begin by creating a controller class. In Solution  Explorer, right-click the Controllers folder  and then click Add,  then Controller.

    In the Add Scaffold dialog box, click MVC 4 Controller - Empty, and then click Add.
    and name your controller "HomeController" and click Add.Now we will write the following code:
    using System.Web;
    using System.Web.Mvc; 
    namespace MyApp.Controllers 
        public class HomeController : Controller 
            // GET: /Home/ 
            public string Index() 
                return "Hi guest this is index section; 
            // GET: /Home/Welcome/ 
            public string Welcome() 
                return "This is the Welcome action method..."; 

    We run this project then it produced following results:

      Modified On Apr-11-2018 01:09:31 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.