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.
2. 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/
4. Goals for this talk Present an overview of ASP.NET MVC MVC vsWebforms. Why? What is the MVC paradigm? Controllers and Action Methods Views Html Helpers Models Model Binding Routing Best Practices
5. 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
8. 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
9. ASP.NET Web Forms Traditional urlhttp://www.yoursite.com/admin/menu.aspx
12. 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.
13. Model The model is the representation of your data. Business Logic
14. 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
15. 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.
16. Model Binding Takes data from an html form and creates an object. No need to write plumbing code
17. 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.
18. Where can I get it? http://www.asp.net/mvc/download/ http://www.microsoft.com/express/Web/
20. What did we just talk about? Present an overview of ASP.NET MVC MVC vsWebforms. Why? What is the MVC paradigm? Controllers and Action Methods Views Html Helpers Models Model Binding Routing Best Practices
Controller gets data from the model, Gives it to a view.Controller doesn’t care where model gets data, and likewise controller doesn’t care how the view renders.Each component only cares about itself. Easy to swap out.Benefits :Separation of ConcernsTestabilityEasy to modifyLack of ComplexityFlow:Request comes through. Controller class handles the request, fetching data from the model. Controller then sends that data to the View and the result is given to the framework for rendering