Getting Started with ASP.NET MVC

21
Getting Started with ASP.NET MVC

description

This is an introductory session that will give you an overview of asp.net mvc. We'll examine some of the basic principles behind the framework and contrast it with asp.net webforms. The session will cover topics such as model binding, routing and rad development using asp.net mvc.

Transcript of Getting Started with ASP.NET MVC

Page 1: Getting Started with ASP.NET MVC

Getting Started with ASP.NET

MVC

Page 2: Getting Started with ASP.NET MVC

Housekeeping

*Stuttering is a communication disorder involving disruptions, or “disfluencies,” in a person’s speech.

*Across all cultures, roughly 1% of people currently has a stuttering disorder.

*http://westutter.org/

Page 3: Getting Started with ASP.NET MVC

Who am I?

Hattan ShobokshiSenior Software Engineer

[email protected]

http://speakerrate.com/hattan

Page 4: Getting Started with ASP.NET MVC

Goals for this talk

* Present an overview of ASP.NET MVC

* MVC vs Webforms. Why?

*What is the MVC paradigm?

*Controllers and Action Methods

*Views

*Html Helpers

*Models

*Model Binding

*Routing

*Best Practices

Page 5: Getting Started with ASP.NET MVC

* A new web development framework that allows you to develop web applications on the Microsoft stack using an MVC Architecture.

* Is NOT a replacement for traditional ASP.NET web forms.

* Web Forms vs MVC

* Current Version is MVC3.

* MVC2 and MVC3 are extension of MVC1.

* MVC1 and MVC2 - .NET Framework 3.5 & 4.0

* MVC3 4.0 ONLY

* Visual Studio Tooling Support

* Convention over configuration

What is ASP.NET

MVC

Page 6: Getting Started with ASP.NET MVC

*What is MVC?

Page 7: Getting Started with ASP.NET MVC
Page 8: Getting Started with ASP.NET MVC

Why should I use ASP.NET MVC?

*Testability

*Model Binder is awesome!

*No Viewstate

*SEO friendly url’s

*Complete control over Html output

*Easier integration with Jquery

*Better Separation of Concerns

Page 9: Getting Started with ASP.NET MVC

*ASP.NET Web Forms

*Traditional urlhttp://www.yoursite.com/admin/menu.aspx

Page 10: Getting Started with ASP.NET MVC

*ASP.NET MVC

*http://www.yoursite.com/admin/menu

*Admin is not a folder, but a class called AdminController

*Menu is not a file, but a Method in the AdminController Class

Page 11: Getting Started with ASP.NET MVC

*DEMO

Page 12: Getting Started with ASP.NET MVC

*Routing

*Route engine parses url’s, extracts any data and sends it off to controller

*Create extremely customizable routes

*Route table defines routes in global.asax

*You do not need to define a route to handle querystring parameters. They are automatically mapped.

Page 13: Getting Started with ASP.NET MVC

*Model

*The model is the representation of your data.

*Business Logic

Page 14: Getting Started with ASP.NET MVC

*Views

*No Code behind

*Action methods by default call views with the same name. (Convention over configuration)

*Views are not tied to a specific action method or controller.

*Views should be dumb (shouldn’t contain any application logic, only rendering logic)

*Views can be strongly typed

Page 15: Getting Started with ASP.NET MVC

*Html Helpers

*Html helpers are extension methods that generate html. @Html.TextBox(“Name”,”Bob”)

*Html helpers are NOT controls, they simply generate html markup (strings)

*You can create your own Html Helper.

Page 16: Getting Started with ASP.NET MVC

*Model Binding

*Takes data from an html form and creates an object.

*No need to write plumbing code

Page 17: Getting Started with ASP.NET MVC

*Best Practices

*Never include a hard reference in the view

(eg <script src=“../js/jquery.js”></script>)

instead use url.content like so<script src=“<%=Url.Content(“~/js/jquery.js”)%>”></script>)

*Never have big if then else in view, put it in an html helper

*Add namespace to web.config so you don’t have to keep referencing it on each page

* The difference between routing name and class name.

Page 18: Getting Started with ASP.NET MVC

Where can I get it?

http://www.asp.net/mvc/download/

http://www.microsoft.com/express/Web/

Page 19: Getting Started with ASP.NET MVC

Resources

*http://www.asp.net/learn/mvc/

*http://www.asp.net/learn/mvc-videos/

*Pro ASP.NET MVC Framework by Steven Sanderson

*Asp.net mvc Forumshttp://forums.asp.net/1146.aspx

*http://haacked.com/

Page 20: Getting Started with ASP.NET MVC

What did we just talk about?

* Present an overview of ASP.NET MVC

* MVC vs Webforms. Why?

*What is the MVC paradigm?

*Controllers and Action Methods

*Views

*Html Helpers

*Models

*Model Binding

*Routing

*Best Practices

Page 21: Getting Started with ASP.NET MVC

The End

Thank you!