Top Banner
MVC ASP .Net VS 2010 Jayant Jindal [email protected] om
15
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mvc 4 0_jayant_jindal_28082010

MVC ASP .Net VS 2010

Jayant [email protected]

Page 2: Mvc 4 0_jayant_jindal_28082010

Key Take Aways…

• Why MVC?• What is MVC?• How to Implement MVC?• ASP .Net VS 2010 MVC Enhancements…

Page 3: Mvc 4 0_jayant_jindal_28082010

Why MVC?

• Easier code maintenance and support.• Supports automated unit testing tools such as

NUnit, MBUnit,...• Decouple business and presentation

application layers.• Web-based thin-client application.• User interface logic tends to change more

frequently than business logic.

Page 4: Mvc 4 0_jayant_jindal_28082010

Patterns…• Page Controller Pattern

• ASP.NET web forms are the code-behind classes.• Each page has a code-behind class.• URL requested by the client is directly handled by

individual pages.• All page code is in the code-behind files.• By default, ASP.NET is page controller based.

Page 5: Mvc 4 0_jayant_jindal_28082010

Patterns…• Front Controller Pattern

• MVC is based on a front controller design.• Centralized controller instead of multiple

controllers.• Trap all client requests, and controller decides

which view or .aspx to render.

Client Request

Central Controller

MyPage2 ASPXHTML View

MyPage1 ASPXHTML View

Page 6: Mvc 4 0_jayant_jindal_28082010

What is MVC?• Model: This refers to the data that is shown in the UI.

Data can come from different sources.• View: This refers to the UI components that will show the

model data.• Controller: This controls when to change the view, based

on user actions.• MVC design is not a replacement to the n-tier

architecture.• 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.

Page 7: Mvc 4 0_jayant_jindal_28082010

Basics of MVC• Model is independent of the view and the controller.

• Controller is associated with the view, allowing to change views independent of the controller.

• View depends on the model, and is updated when the model's state has changed.

Controller View

Model

Page 8: Mvc 4 0_jayant_jindal_28082010

REST: Representation State Transfer• Architectural pattern used to identify and fetch

resources from networked systems. e.g. www.• Sharing of resources via unique identifiers.• No need to check for a page postback.• Foll. code is not supported in REST approach:

btnSave_Cick(){Response.Redirect("~/MyPage.aspx");}

Page 9: Mvc 4 0_jayant_jindal_28082010

ASP.NET MVC Framework• In MVC framework, URL routing is used. • 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

• ASPX pages are kind of view engine, nothing else.

• ASP.NET MVC framework is not a replacement or upgrade of web forms, but merely another way of programming.

Page 10: Mvc 4 0_jayant_jindal_28082010

URL Routing Engine• Standard ASP.NET model

• MVC Framework model:

Client browser requests URL

http://myapp/CustomerList.asp

x

CustomerList.aspx processed by

ASP.NET runtime and HTML

returned to IIS

IIS

Client browser requests URL

http://myapp/Customer/List

ASP.NET runtime

IIS Controller Class

View (ASPX)

Model Class

Page 11: Mvc 4 0_jayant_jindal_28082010

MVC 2.0 Enhancements• Includes ASP.NET MVC 2 framework.• Strongly Typed Html Helpers: view model

level error instead of all validation Errors ASP.NET MVC 1 : <%= Html.TextBox(“ClassId”,

Model.ClassId) %> ASP.NET MVC 2 : <%= Html.TextBoxFor(model => model.ClassId) %>

• Model Validation: Validation logic is always enforced on the server, and if needed can be done on client via JavaScript.

Page 12: Mvc 4 0_jayant_jindal_28082010

MVC 2.0 Framework Enhancements• Areas Support: Group controllers and views

into sections.• 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.:

Page 13: Mvc 4 0_jayant_jindal_28082010

MVC 2.0 Framework Enhancementsusing System.ComponentModel;Using System.ComponentModel.DataAnnotations;namespace MvcApplication1.Models{public class Product{public int Id { get; set; }[Required][StringLength(10)]public string Name { get; set; }[DisplayName("Price")][Required][RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]public decimal UnitPrice { get; set; } }}

Page 14: Mvc 4 0_jayant_jindal_28082010

Suggested Reading…• ASP.Net 3.5 (Application Architecture and Design) by Vivek Thakur

Page 15: Mvc 4 0_jayant_jindal_28082010

Thank You

Questions???

Contact me: [email protected]