Question? Leave a message!




ASP .NET MVC

ASP .NET MVC 9
JadenNorton Profile Pic
JadenNorton,United States,Researcher
Published Date:14-07-2017
Website URL
Comment
ASP .NET MVC 5 Nemanja Kojic, MScEE 1What is MVC? • Model-View-Controller (MVC) • Standard Architectural Pattern • Separation of concerns: model, view, controller 2 of 114ASP .NET MVC Framework • An alternative to ASP .NET Web Forms • Presentation framework – Lightweight – Highly testable – Integrated with the existing ASP .NET features: • Master pages • Membership-Based Authentication • ... 3 of 114ASP .NET MVC Framework Components • Models – Business/domain logic – Model objects, retrieve and store model state in a persistent storage (database). • Views – Display application’s UI – UI created from the model data • Controllers – Handle user input and interaction – Work with model – Select a view for rendering UI 4 of 114When to use MVC approach? • Advantages: – Easier to manage complexity (divide and conquer) – It does not use server forms and view state – Front Controller pattern (rich routing) – Better support for test-driven development – Ideal for distributed and large teams – High degree of control over the application behavior 5 of 114ASP .NET MVC Features • Separation of application tasks – Input logic, business logic, UI logic • Support for test-driven development – Unit testing – No need to start app server • Extensible and pluggable framework – Components easily replaceable or customized (view engine, URL routing, data serialization,…) 6 of 114ASP .NET MVC Features (cont.) • Support for Dependency Injection (DI) – Injecting objects into a class – Class doesn’t need to create objects itself • Support for Inversion of Control (IOC) – If an object requires another object, the first should get the second from an outside source (configuration file) 7 of 114ASP .NET MVC Features (cont.) • Extensive support for ASP .NET routing • Building apps with comprehensible and searchable URLs • Customizable URLs – Adapted to work well with search engines – Adapted to REST addressing – Decoupled from resource files • Use of existing ASP .NET features (backward compatibility) 8 of 114ASP .NET MVC App Structure • URLs mapped to controller classes • Controller – handles requests, – executes appropriate logic and – calls a View to generate HTML response • URL routing – ASP .NET routing engine (flexible mapping) – Support for defining customized routing rules – Automatic passing/parsing of parameters 9 of 114ASP .NET App Structure • No Postback interaction • All user interactions routed to a controller • No view state and page lifecycle events 10 of 114MVC App Execution • Entry points to MVC: – UrlRoutingModule and MvcRouteHandler • Request handling: – Select appropriate controller – Obtain a specific controller instance – Call the controller’s Execute method 11 of 114MVC App Execution - stages • Receive first request for the application – Populating RouteTable • Perform routing • Create MVC Request handler • Create controller • Execute controller • Invoke action • Execute result – ViewResult, RedirectToRouteResult, ContentResult, FileResult, JsonResult, RedirectResult 12 of 114MVC App Execution 13 of 114BUILDING VIEW PAGES USING RAZOR LANGUAGE RAZOR ENGINE 14 of 114Razor Engine • A new view-engine • Optimized around HTML generation • Code-focused templating approach 15 of 114Razor Engine – Design goals • Compact, Expressive and Fluid • Easy to learn • It is not a new language • Works with any text editor • Great Intellisense • Unit-testable – Testing views without server, controllers… 16 of 114Razor – HelloWorld • Uses for razor file Razor blocks .aspx file 17 of 114Loops and Nested HTML Razor syntax .aspx syntax 18 of 114If Blocks and Multi-line Statements Multi-Token IF statement statement Variables can span Multi-line Variables multiple server statement code blocks 19 of 114Integrating Content and Code Parser examines right-hand side of character. Identifying nested content with HTML block tag 20 of 114