110 likes | 308 Views
ASP.NET MVC 2.0. 2009-12-23. Intro. http://localhost/Main/Index. class MainContoller { function Index() {. REQUEST. CONTROLLER. RESPONSE. HTML CSS JavaScript. raw data. VIEW. MODEL. Sample. MainController.cs. public class MainController : Controller {
E N D
ASP.NET MVC 2.0 2009-12-23
Intro http://localhost/Main/Index class MainContoller { function Index() { ... REQUEST CONTROLLER RESPONSE HTML CSS JavaScript raw data VIEW MODEL
Sample MainController.cs public class MainController : Controller { public ActionResult Index(int id) { var model = new MainModel(id); return View(“Index”, model); } } Index.aspx MainModel.cs <html> <body> <h1><%= Model.Title %></h1> <p><%= Model.Content %></p> </body> </html> public class MainModel { public int Id; public string Title; public string Content; }
ASPX vs PHP MainController.php MainController.cs class MainController implements Controller { public function Index($id) { $model = new MainModel($id); return $this->View(“Index”, model); } } public class MainController : Controller { public ActionResult Index(int id) { var model = new MainModel(id); return View(“Index”, model); } } Index.aspx Index.php <html> <body> <h1><%= Model.Title %></h1> <p><%= Model.Content %></p> <img src=“<%= Html.FindFile(“image.jpg”) %>” /> <div><%= ViewData[“Foo”] %></div> </body> </html> <html> <body> <h1><?= $Model->Title ?></h1> <p><?= $Model->Content ?></p> <img src=“<?= $Html->FindFile(“image.jpg”) ?>” /> <div><?= $ViewData[“Foo”] ?></div> </body> </html>
ASP.NET MVC 1.0 • community (ms-pl) • MVC frame • url rewriting and routing • basic validation • helpers (html generators) • page caching
ASP.NET MVC 2.0 • templated helpers • areas • support for Data Annotations • client validation • AsyncController • strongly-typed input helpers • bug fixes, minor features
Sample 1 public class ProductViewModel { [Price(MinPrice = 1.99)] public double Price { get; set; } [Required] public string Title { get; set; } }
Sample 2 [ChildActionOnly] public ActionResult Menu() { var menu = ... return PartialView(menu); } Partial rendering <%= Html.Action("Menu") %> - builds a string and then sends to output <%= Html.RenderAction("Menu") %> - direct outtput
Community developers • extra helpers • T4 templates • localization • programming techniques • blogs, tutorials • partial caching (donut caching) • webshop (cart, order, PayPal) • Oxite
Road map • MVC (pattern) – 1979 • ASP.NET MVC 1.0 – 17th mar 2009 • ASP.NET MVC 2.0 RC – 17th dec 2009 • ASP.NET MVC 2.0 – ?, integrated in VS2010
Links • http://haacked.com • http://www.asp.net/mvc/gallery • http://aspnet.codeplex.com • Wikipedia: MVC