mortal kombat! asp.net mvc vs asp.net webforms – asp.net mvc is amazing
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.ContactsTRANSCRIPT
Mortal Kombat! ASP.NET MVC vs ASP.NET Webforms – fight!!
ASP.NET MVC IS AWESOME!!
[email protected]@Tinytoothttp://www.tom-walker.ca/
Shu Ha Ri”first learn, then detach, and finally transcend”
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
But, first lets talk Github
Basics of MVC
View
Model
Controller
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; } }
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’
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!!!
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
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/
DEMO TIME
Questions?”There is no such thing as a stupid question”
[email protected]@Tinytoothttp://www.tom-walker.ca/
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