13
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – fight!! ASP.NET MVC IS AWESOME!! [email protected] @Tinytoot http://www.tom-walker.ca/

Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Embed Size (px)

DESCRIPTION

Slides from London .NET Developers session "Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – fight!!". I was defending ASP.NET MVC. The code for the demo can be found here: https://github.com/LdnOntNetDevs/MVC.Contacts

Citation preview

Page 1: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – fight!!

ASP.NET MVC IS AWESOME!!

[email protected]@Tinytoothttp://www.tom-walker.ca/

Page 2: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Shu Ha Ri”first learn, then detach, and finally transcend”

Page 3: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Agenda

• Basics of MVC and the Moving Parts

• Creating and Configuring Models

• Controllers in ASP.NET MVC 4• Razor Views• Working with data using EF6• Bootstrap basics

Page 4: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

But, first lets talk Github

Page 5: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Basics of MVC

View

Model

Controller

Page 6: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Creating and Configuring Models public class Contact

{ [ScaffoldColumn(false)] [Key] public int ContactId { get; set; } [Required] public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } public string Email { get; set; } public string Twitter { get; set; }

public virtual ICollection<ContactPhone> PhoneNumbers { get; set; } }

Page 7: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Controllers in ASP.NET MVC 4• It is a class• Derives from the base

System.Web.Mvc.Controller class• Generates the response to the browser

request• Controllers are not bound to any specific view

and so can be reused for multiple views.• Action Results Types (ie ViewResult,

RedirectResult, JsonResult)• Scaffolding is the ‘secret sauce’

Page 8: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Razor Views• Most of the Controller Actions return views• The path to the view is inferred from the name of

the controller and the name of the controller action.

• \Views\ControllerName\ControllerAction.aspx• A view is a standard HTML document that can

contain JavaScript.• Yes, you can have C# code in the view @{ }• Keep views as simple and clean as

possible!!!

Page 9: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Working with data using EF6• EF is essentially an O/R mapping tool• Async Query and Save• Much faster to build the DAL (love not writing the

SQL queries!)• Much easier to maintain• Code-First Development with EF or use Scheme

First or Model First approaches• Access a relational database with strongly typed

LINQ queries

Page 10: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Bootstrap basics• Front-end Javascript/CSS Framework• Baked into ASP.NET MVC• Mobile first • Bootstrap Normalization with CSS across

different browser• _Layout.cshtml is where the Bootstrap CSS is

called within the MVC project• 12 is the magic number for Grid Layouts • Use this http://getbootstrap.com/css/

Page 11: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

DEMO TIME

Page 12: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Questions?”There is no such thing as a stupid question”

[email protected]@Tinytoothttp://www.tom-walker.ca/

Page 13: Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – ASP.NET MVC is amazing

Resources• Getting Started with ASP.NET MVC 5• http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started

• The basics of using Entity Framework 5 to display and edit data in an ASP.NET MVC 4 application.

• http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4

• pluralsight - Building Applications with ASP.NET MVC 4

• http://pluralsight.com/training/Courses/TableOfContents/mvc4-building