Z 5 ) MVC (Model view Controller)

 MVC (Model view Controller)

  1.   Model View Controller
  2.   The first version of  MVC is called MVED(Model View Editor)
  • MVC is to multi layer architecture 
  1. Model         (class and variables)
  2. View          (.cshtml)
  3. Controller   (Logic building)
  • MVC is directly operate html page in this reason it is called light weight environment.

  • MVC Block Diagrame 
  1.  .NET Framework
  2.  ASP.NET MVC
  3. ASP.Net Webform
  • Benefits of MVC application
  1. It is manage complex application
  2. Direct control use in html
  3. It provide test driven development testing to (url http/data)

  • MVC Lifecycle
    There are two types of lifecycle
  1. Application LIfecycle :- Application lifecycle is use to process the application programe between to end stage.
  2. Request Lifecycle       :-  Request lifecycle handing the put output state through http
  • MVC Folder Architecture
  1. Model
  2. View
  3. controller
  4. App_Data
  5. App_Start

Q ) How to Create a first application

0

Steps :- Create folder -- file -- new -- project -- Visual C# -- Asp.net web application (.net framework) -- Browser (Selectfolder) -- ok -- select template (MVC) -- ok

Q ) How to create controller
Steps :- Solution explorer -- right click on controller -- add -- controller -- Installed (Controller) -- MVC 5 controller -- empty -- add -- ControllerName(StudentConroller) -- Add.

  • All controller name with controller keyword
  • Controller refrence predfined library :- Using System.Web.MVC
  • ActionResult can't returning data to webform
  • IF returning data to controller to webform then we have to use string function (modifier)

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

using WebApplication1.Models; //add folder refrence library

namespace WebApplication1.Controllers
{
    public class StudentController : Controller
    {
        IList<Stud> stulist = new List<Stud>
        {
            new Stud
            {
                id=1,
                name ="Sourabh",
                city ="nagpur"
            },
            new Stud
            {
                id=2,
                name ="Ajay",
                city ="Bhuneshwar"
            },
            new Stud
            {
                id=3,
                name ="Pawan",
                city ="Kolhapur"
            },
            new Stud
            {
                id=4,
                name ="Golu",
                city ="Kalmeshwar"
            }
        };
        // GET: Student
        public string Index()
        {
            return "this is my first application programe";
        }
        public ActionResult VieStud()
        {
            return View(stulist);
        }
    }
}

Q ) How to run controller
Using url path :- http://localhost:53645/Student   
(StudentController select only controller name)


Q ) how to create Model
Steps :- goto solution explorer -- right click on Model -- Add -- Class -- classname -- add.

  • All variable inside the class(Model) we have to use variable property (Get , Set) all variable is use to (Public) specifier 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
    public class Stud
    {
       // create var using public modifier
        public int id { get; set; }
        public string name { get; set; }
        public string city { get; set; }
    }
}

Q ) How Create View
Steps :- create View using controller -- goto the controller page -- right click on Index() -- Add view  -- View name (Index) -- Template (List) -- Model Class (choose class) -- Use layout page (view/Shared/Layout.cshtml) -- ok

Result









Comments

Popular posts from this blog

DATA CONTROL ( Gridview , Repeater , Formview , DataList , Detailsview , Listview )

Z 8 ) MVC HTMLHELPER METHOD AND ACTIONLINK (how to use css ,atrributes,style in css)