Mvc 4 0_jayant_jindal_28082010


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mvc 4 0_jayant_jindal_28082010

  1. 1. MVC ASP .Net VS 2010<br />Jayant Jindal<br /><br />
  2. 2. Key Take Aways…<br />Why MVC?<br />What is MVC?<br />How to Implement MVC?<br />ASP .Net VS 2010 MVC Enhancements…<br />
  3. 3. Why MVC?<br />Easier code maintenance and support.<br />Supports automated unit testing tools such as NUnit, MBUnit,...<br />Decouple business and presentation application layers.<br />Web-based thin-client application.<br />User interface logic tends to change more frequently than business logic.<br />
  4. 4. Patterns…<br />Page Controller Pattern<br /><ul><li>ASP.NET web forms are the code-behind classes.
  5. 5. Each page has a code-behind class.
  6. 6. URL requested by the client is directly handled by individual pages.
  7. 7. All page code is in the code-behind files.
  8. 8. By default, ASP.NET is page controller based.</li></li></ul><li>Patterns…<br /><ul><li>Front Controller Pattern
  9. 9. MVC is based on a front controller design.
  10. 10. Centralized controller instead of multiple controllers.
  11. 11. Trap all client requests, and controller decides which view or .aspx to render.</li></ul>Client Request<br />Central Controller<br />MyPage2 ASPX<br />HTML View<br />MyPage1 ASPX<br />HTML View<br />
  12. 12. What is MVC?<br /><ul><li>Model: This refers to the data that is shown in the UI. Data can come from different sources.
  13. 13. View: This refers to the UI components that will show the model data.</li></ul>Controller: This controls when to change the view, based on user actions.<br />MVC design is not a replacement to the n-tier architecture.<br />The model, the view, and the controller are not related directly to the layers, or to the physical tiers; they are logical components that operate together in a certain pattern.<br />
  14. 14. Basics of MVC<br /><ul><li>Model is independent of the view and the controller.</li></ul>Controller is associated with the view, allowing to change views independent of the controller.<br />View depends on the model, and is updated when the model's state has changed.<br />Controller<br />View<br />Model<br />
  15. 15. REST: Representation State Transfer<br />Architectural pattern used to identify and fetch resources from networked systems. e.g. www.<br />Sharing of resources via unique identifiers.<br />No need to check for a page postback.<br />Foll. code is not supported in REST approach:<br />btnSave_Cick()<br /> {<br />Response.Redirect("~/MyPage.aspx");<br /> }<br />
  16. 16. ASP.NET MVC Framework<br />In MVC framework, URL routing is used. <br />URLs are used based on the settings in a config file. e.g.: http://localhost/customer/list/ instead of traditional URL like: http://localhost/CustomerList.aspx<br />ASPX pages are kind of view engine, nothing else.<br />ASP.NET MVC framework is not a replacement or upgrade of web forms, but merely another way of programming.<br />
  17. 17. URL Routing Engine<br /><ul><li>Standard ASP.NET model
  18. 18. MVC Framework model:</li></ul>CustomerList.aspx processed by ASP.NET runtime and HTML returned to IIS<br />Client browser requests URL<br />http://myapp/CustomerList.aspx<br />IIS<br />Client browser requests URL<br />http://myapp/Customer/List<br />ASP.NET runtime<br />IIS<br />Controller Class<br />Model Class<br />View (ASPX)<br />
  19. 19. MVC 2.0 Enhancements<br />Includes ASP.NET MVC 2 framework.<br />Strongly Typed Html Helpers: view model level error instead of all validation Errors<br /> ASP.NET MVC 1 : <%= Html.TextBox(“ClassId”, Model.ClassId) %><br />ASP.NET MVC 2 : <%= Html.TextBoxFor(model => model.ClassId) %><br />Model Validation: Validation logic is always enforced on the server, and if needed can be done on client via JavaScript.<br />
  20. 20. MVC 2.0 Framework Enhancements<br />Areas Support:Group controllers and views into sections.<br />Data-Annotation Attribute Validation Support: Enable to perform validation by adding one or more attributes. (Add References: Microsoft.Web.Mvc.DataAnnotations.dll and System.ComponentModel.DataAnnotations.dll assemblies. E.g.:<br />
  21. 21. MVC 2.0 Framework Enhancements<br />using System.ComponentModel;<br />Using System.ComponentModel.DataAnnotations;<br />namespace MvcApplication1.Models<br />{public class Product<br />{public int Id { get; set; }<br />[Required]<br />[StringLength(10)]<br />public string Name { get; set; }<br />[DisplayName("Price")]<br />[Required]<br />[RegularExpression(@"^$?d+(.(d{2}))?$")]<br />public decimal UnitPrice { get; set; } }}<br />
  22. 22. Suggested Reading…<br /><ul><li>ASP.Net 3.5 (Application Architecture and Design) by Vivek Thakur</li></li></ul><li>Thank You<br />Questions<br />???<br />Contact me: <br /><br />