CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer...

22
CS 415 N-Tier Application Development By Umair Ashraf June 28 ,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture for ASP.NET

Transcript of CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer...

Page 1: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

CS 415 N-Tier Application Development

By Umair Ashraf

June 28 ,2013

National University of Computer and Emerging Sciences

Lecture # 5

Microsoft MVC3 Architecture for ASP.NET

Page 2: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Agenda/Contents for Today’s Lecture

Design Patterns Review Class Activity Introduction to Microsoft MVC framework History Advantages Practical Demonstration Quiz Announcement

Page 3: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Introduction to MVC framework

ASP.NET MVC is a framework for building web applications that applies the general ModelView Controller pattern to the ASP.NET framework.

Page 4: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Components of ASP.NET MVC ModelsThese are the classes that represent the domain you are

interested in.

With ASP.NET MVC, this is most likely a Data Access Layer of some kind using a tool like Entity Framework or NHibernate combined with custom code containing domain-specific logic

ViewThis is a template to dynamically generate HTML

ControllerThis is a special class that manages the relationship between

the View and Model.

Page 5: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

History ASP.NET MVC1 Feb 2007 by Scott Guthrie

Presented in a conference on the East Coast of the United States.

ASP.NET MVC2 March 2010

More Features like UIHelpers, Attribute validations etc

ASP.NET MVC3 January 2011

New Razor View Engine,Rich Javascript support etc.

ASP.NET MVC4 October 2012 Mobile development support , enhancements etc

Page 6: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Creating an ASP.NET MVC 3 Application

Page 7: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Creating an ASP.NET MVC 3 Application

Page 8: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

The New ASP.NET MVC 3 Dialog

Page 9: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

MVC APPLICATION STRUCTURE

Page 10: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Controllers Controllers within the MVC pattern are

responsible for responding to user input, often making changes to the model in response to user input. In this way, controllers in the MVC pattern are concerned with the flow of the application, working with data coming in, and providing data going out to the relevant view.

Page 11: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

A Simple Example: The Home Controller

Page 12: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Home Controller Classusing System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;namespace MvcMusicStore.Controllers{Public class HomeController : Controller{public ActionResult Index(){ViewBag.Message = “I like cake!”;return View();}public ActionResult About(){return View();}}}

Page 13: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Creating the New Controller

Page 14: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Action Methods public class StoreController : Controller { // // GET: /Store/ public string Index() { return “Hello from Store.Index()”; } // // GET: /Store/Browse public string Browse() { return “Hello from Store.Browse()”; } // // GET: /Store/Details public string Details() { return “Hello from Store.Details()”; } } }

Page 15: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Parameters in Controller Actions // // GET: /Store/Browse?genre=?Disco public string Browse(string genre) { string message = HttpUtility.HtmlEncode(“Store.Browse,

Genre = “ + genre); return message; }

Page 16: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Parameters in Controller Actions

Page 17: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Razor View Engine Razor is the first major update to rendering

HTML since ASP.NET 1.0 shipped almost a decade ago. The default view engine used in MVC 1 and 2 was commonly called the Web Forms View Engine, because it uses the same ASPX/ASCX/MASTER files and syntax used in Web Forms

Page 18: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

What is Razor? Razor is the response to one of the most

requested suggestions received by the ASP.NET MVC feature team — to provide a clean, lightweight simple view engine that didn’t contain the “syntactic cruft” contained in the existing Web Forms View Engine.

Many developers felt that all that syntactic noise

required to write a view created friction when trying to read that view.

Page 19: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

View Example @{ Layout = null; } <!DOCTYPE html> <html> <head><title>Sample View</title></head> <body> <h1>@ViewBag.Message</h1> <p> This is a sample view. It’s not much to look at, but it gets the job done. </p> </body> </html>

Page 20: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

ASP.NET MVC life cycle

Page 21: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Announcements

Quiz 1 (Design Patterns) Tomorrow Saturday 29th July 2013 in class

Assignment 1 Due Saturday 29th July 2013 in class

Page 22: CS 415 N-Tier Application Development By Umair Ashraf June 28,2013 National University of Computer and Emerging Sciences Lecture # 5 Microsoft MVC3 Architecture.

Reference Material

Text Book :Professional ASP.NET MVC3 By WROX(EBook uploaded on website )

Other References :http://www.w3schools.com/aspnet/mvc_intro.asphttp://www.asp.net/mvc/tutorials