1 / 31

Introduction to ASP.NET MVC 3.0 with Razor View Engine

Introduction to ASP.NET MVC 3.0 with Razor View Engine. By: Shahid Maqsood. Session Agenda. What is ASP.NET MVC? What is MVC? Is it deprecating WebForms ? What are its value propositions? Is ASP.NET MVC right for you? Can it ease some web development pain you’re currently having ?.

randi
Download Presentation

Introduction to ASP.NET MVC 3.0 with Razor View Engine

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to ASP.NET MVC 3.0 with Razor View Engine • By: ShahidMaqsood http://kb.nextbridge.org

  2. Session Agenda • What is ASP.NET MVC? • What is MVC? • Is it deprecating WebForms? • What are its value propositions? • Is ASP.NET MVC right for you? • Can it ease some web development pain you’re currently having? http://kb.nextbridge.org

  3. ASP.NET Then… One web application framework to rule them all… Caching Modules Globalization Pages Controls Master Pages Profile Roles Membership Intrinsics Handlers Etc. http://kb.nextbridge.org

  4. Asp.Net Now Runtime ASP.NET Dynamic Data Presentation ASP.NET WebForms ASP.NET MVC ASP.NET Core Dynamic Data? What is it? http://kb.nextbridge.org

  5. Asp.Net Dynamic Data • ASP.NET Dynamic Data lets you create extensible data-driven Web applications by inferring at run time the appearance and behavior of data entities from the database schema and deriving UI behavior from it. • Dynamic Data supports scaffolding which is a way to automatically generate Web pages for each table in the database. • RoR guys will know it very well. • http://msdn.microsoft.com/en-us/library/ee845452.aspx

  6. Options are good… WebFormsis great, but options are good… So, Asp.Net MVC is another option for Asp.Net Development…

  7. Lets talk about some of the areas from Asp.Net Web Forms that Asp.Net MVC addresses… http://kb.nextbridge.org

  8. No real role, responsibility… Master Page Control Control UI Presentation Logic Business Logic Data Access Control Page Control Control Control Control Control Who does what? How and when? http://kb.nextbridge.org

  9. No real role, responsibility… • The level of abstractionthat WebForms provides has a lot of benefits to it, but it doesn’t provide any framework-level guidance in terms of what should do what and when. • Between your pages, master pages, user controls, server controls, and custom controls, you can end up with a mixture of HTML, data access code, and business logic. • Yes, we can avoid above issues but it will be the task of the developer. http://kb.nextbridge.org

  10. Control abstractions can be negative… http://kb.nextbridge.org

  11. Unit testing… It isn't easy enough to test… UI Logic http://kb.nextbridge.org

  12. So how does ASP.NET MVCdiffer? • What is it about ASP.NET MVC that differentiates itself from WebForms? • What value propositions does it provide and how does it benefit users? • The primary thing is that it embraces the MVCpattern at the architectural level, and is generally just about getting out of the way of the developer, allowing you to have full control over the areas you want/need to. http://kb.nextbridge.org

  13. What is MVC? Lets talk about MVC pattern in general. http://kb.nextbridge.org

  14. MVC = Model-View-Controller The Model-View-Controller (MVC) pattern is an architectural design principle that separates the components of a Web application. This separation gives you more control over the individual parts of the application, which lets you more easily develop, modify, and test them. Controller (Input) View (Presentation) Model (Logic) Separation of concerns! http://kb.nextbridge.org

  15. MVC = Model-View-Controller • The Controller is responsible for handling all user input. Once input has been received, the Controller will perform any operations/actions it needs to, which might include interacting with the Model. • The Model represents the core concern/logic of the application. Once the Controller retrieves some model data and performs any work with the model, it constructs a presentation model that describes the model in terms the View can understand. • The Viewis the visual representation of the model. It presents the model data to the actual user in a way that is meaningful. In a web application, this would typically be HTML. With these three pieces in place, your presentation layer becomes cleanly separated in such a way that each component can be developed/tested independently. http://kb.nextbridge.org

  16. How does Asp.Net MVC look? Controller Controller Handles input (HTTP requests) Request View View Visually represents the model Response http://kb.nextbridge.org

  17. How Asp.Net MVC work? • So what does MVC look like when implemented over the web? • When an HTTP request comes into the application it is mapped to a controller. Remember as we mentioned in the previous slide, in the MVC design pattern, the controller is the piece of the trifecta that handles all user input. In the case of a web application, user input is represented as HTTP requests. • Once the controller has received input, it performs whatever operations it needs to and then assembles a presentation model. http://kb.nextbridge.org

  18. How does Asp.Net MVC work? • The controller then takes the model and passes it off to the view. Remember that the view is simply a visual representation of the model. • The view then “transforms” the model into whatever format it uses to represent it. In a web application, this would typically be HTML. • The view then serves the request by responding with its visual representation. http://kb.nextbridge.org

  19. What are the tenets of ASP.NET MVC? http://kb.nextbridge.org

  20. Framework Goals • Frictionless Testability • The framework should not cause any friction. • This is very important if you want to seriously perform long-term unit testing on an application, because if developers were constantly running into points of friction when trying to test, they would eventually abandon it. • Tight control over <markup> • ASP.NET MVC doesn’t contain any server controls or high-level abstractions that mask their underlying rendering. • When you develop an ASP.NET MVC application, you have complete control over the markup. ASP.NET MVC does include some HTML helpers that “hide” away some HTML, but they are at the most basic level of rendering (i.e. just an <input> element).

  21. Framework Goals • Leverage the benefits of ASP.NET • Because ASP.NET MVC is built on top of the core ASP.NET runtime, you still have plenty of old-friends that can be used (i.e. profiles, membership, roles, caching). All of the same intrinsic you’ve always known are still valid and used heavily. • Conventions and guidance • ASP.NET MVC comes with a set of predefined conventions that make the use of it much easier, without the need to for tons of configuration. It also provides framework-level guidance. The idea is that ASP.NET MVC wants to try to lead developers down the pit of success. http://kb.nextbridge.org

  22. Simple MVC Application Lets quickly create a simple asp.net MVC application and examine certain areas of it. http://kb.nextbridge.org

  23. Clean URLs Don’t settle for… /Products.aspx?CategoryID=123 When you can easily have… /Product/Puppies What can be the benefits? • Easy to Remember? • Search Engines? SEO http://kb.nextbridge.org

  24. Extensibility • Replace anything in the execution pipeline that you don’t like. No restriction to stick with default behaviors or conventions. • Since ASP.NET MVC employs separations of concerns throughout its entire API, every task has specific representation that can easily be tweaked/replaced, without having to affect anything else around it. http://kb.nextbridge.org

  25. Extensibility Action Filters Model Binders Any of these can be replaced! Controller Builder Controller Factory Controller Controller Action Invoker View View Engine Action Result http://kb.nextbridge.org

  26. Some benefits of Asp.Net MVC • Part of Asp.Netframework • Easy to test – unit testing • Easy to maintain, upgrade and perform fixes • Can improve collaboration amongst teams • More powerful solutions - you have complete control over markup. • Improved reliability and robustness http://kb.nextbridge.org

  27. When should I use ASP.NET Web Forms vs. ASP.NET MVC? You should use ASP.NET MVC when: • Complete control over markup is important to you and you are willing to put in the extra effort. • You don’t like the abstraction offered by controls. • You don’t mind writing inline code. • You are interested in pattern-based software development and like the separation between layers offered by the MVC pattern. http://kb.nextbridge.org

  28. When should I use ASP.NET Web Forms vs. ASP.NET MVC? You should use ASP.NET Web Forms when: • Creating a website faster is more important to you than complete control over markup. • You like the abstraction offered by controls. • You want to avoid writing inline code. • You are not interested in pattern-based software development and are not familiar with the MVC pattern. http://kb.nextbridge.org

  29. Summary • ASP.NET MVC is a new application option built on top of ASP.NET • WebForms isn’t being deprecated • ASP.NET MVC strives to provide strong, frictionless testability • It places a lot of the control in your hands http://kb.nextbridge.org

  30. Further readings • www.asp.net/mvc • http://msdn.microsoft.com/en-us/library/dd381619.aspx • http://msdn.microsoft.com/en-us/library/dd381612.aspx http://kb.nextbridge.org

  31. Thank you! Questions please? http://kb.nextbridge.org

More Related