Z 5 ) MVC (Model view Controller)
MVC (Model view Controller)
- Model View Controller
- The first version of MVC is called MVED(Model View Editor)
- MVC is to multi layer architecture
- Model (class and variables)
- View (.cshtml)
- Controller (Logic building)
- MVC is directly operate html page in this reason it is called light weight environment.
- MVC Block Diagrame
- .NET Framework
- ASP.NET MVC
- ASP.Net Webform
- Application LIfecycle :- Application lifecycle is use to process the application programe between to end stage.
- Request Lifecycle :- Request lifecycle handing the put output state through http
- MVC Folder Architecture
- Model
- View
- controller
- App_Data
- 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
Comments
Post a Comment