ASP.NET MVC 4.0
By Ram Ayyalaraju
co-founder, CTO ShikshaCLUB.com
Twitter: @RamAyyalaraju
LinkedIn: https://www.linkedin.com/in/ramayyalaraju
Website: ShikshaCLUB.com
email: ram.ayyalaraju@shikshaclub.com
How?
• Using PPT
• Code Snippets and explanations
• Learn By doing
- Video library application
- Lab sessions
- learn by sharing
-
What is new in ASP.NET MVC 4?
• WebAPI
• Task Support for Sync controllers
• Data Base Migrations – What’s New?
• Bundling and Magnifications features – What is new?
• More support for mobile development
In this
Order
WebAPI
• To Embrace HTTP
• Light weight
• Scalable (caching)
• Interoperable(no plugins and works with any client )
• Flexible (custom model bindings, formatters and
filters)
• Can pass-through firewalls
• routes by http methods like get, post, put, delete verbs
Getting Started
• Create a WebAPI Project
• Create an ASP.NET Project
• Create Any Project!
Install NuGet Package
Install-package Microsoft.Asp.Net.WebApi.SelfHost
• Build example project with controllers, views
and basic class lib to work
Routing
• Routes by HTTP methods (Get, Post, Put,
Delete)
• Other Methods available via [AcceptWorps]
• Looks at the start of an action name
WebAPI
Routing cont...
• public class RouteConfig
• {
• public static void RegisterRoutes(RouteCollection routes)
• {
• routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
• routes.MapRoute(
• name: "Default",
• url: "{controller}/{action}/{id}",
• defaults: new { controller = "Home", action = "Index", id =
UrlParameter.Optional }
• );
• }
• }
Routing cont…
• Response in browser
• Response with cURL cmd line util
cURL Download url: http://curl.haxx.se/download.html
ex: http://localhost:1341/api/videos (controller name)
• WebAPI supports multiple Get methods with different
signatures, it’s not true with MVC
• Put/ Delete examples
WebAPI
Content Negotiation
• Core mechanism of HTTP
• Client specifies desired formats using Accept
hearder
• <<Diagram>>
WebAPI
Content Negotiation…cont
GlobalConfiguration.Configuration.Formatters
Count = 4
[0]: {System.Net.Http.Formatting.JsonMediaTypeFormatter}
[1]: {System.Net.Http.Formatting.XmlMediaTypeFormatter}
[2]:
{System.Net.Http.Formatting.FormUrlEncodedMediaTypeF
ormatter}
[3]:
{System.Web.Http.ModelBinding.JQueryMvcFormUrlEncod
edFormatter}
Action Parameters
• How Get, Post, Put, Delete works
• Primitive types (assumed not to be in message
body)
• Complex types (assumed to be in message
boday)
• Only Single model is allowed from message
boday
• <<Implementing PUT and POST by example>>
Async Awaite in MVC 4.0
• What is Async and Await
• Task Parallel Library
• Async Controls
Asycn Awit Example
• <<Example Code walk through >>
Async Controler
• AsyncControls base class
• <<How it’s used in MVC by Example>>

Mvc 4.0

  • 1.
    ASP.NET MVC 4.0 ByRam Ayyalaraju co-founder, CTO ShikshaCLUB.com Twitter: @RamAyyalaraju LinkedIn: https://www.linkedin.com/in/ramayyalaraju Website: ShikshaCLUB.com email: ram.ayyalaraju@shikshaclub.com
  • 2.
    How? • Using PPT •Code Snippets and explanations • Learn By doing - Video library application - Lab sessions - learn by sharing -
  • 3.
    What is newin ASP.NET MVC 4? • WebAPI • Task Support for Sync controllers • Data Base Migrations – What’s New? • Bundling and Magnifications features – What is new? • More support for mobile development In this Order
  • 4.
    WebAPI • To EmbraceHTTP • Light weight • Scalable (caching) • Interoperable(no plugins and works with any client ) • Flexible (custom model bindings, formatters and filters) • Can pass-through firewalls • routes by http methods like get, post, put, delete verbs
  • 5.
    Getting Started • Createa WebAPI Project • Create an ASP.NET Project • Create Any Project! Install NuGet Package Install-package Microsoft.Asp.Net.WebApi.SelfHost • Build example project with controllers, views and basic class lib to work
  • 6.
    Routing • Routes byHTTP methods (Get, Post, Put, Delete) • Other Methods available via [AcceptWorps] • Looks at the start of an action name
  • 7.
    WebAPI Routing cont... • publicclass RouteConfig • { • public static void RegisterRoutes(RouteCollection routes) • { • routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); • routes.MapRoute( • name: "Default", • url: "{controller}/{action}/{id}", • defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } • ); • } • }
  • 8.
    Routing cont… • Responsein browser • Response with cURL cmd line util cURL Download url: http://curl.haxx.se/download.html ex: http://localhost:1341/api/videos (controller name) • WebAPI supports multiple Get methods with different signatures, it’s not true with MVC • Put/ Delete examples
  • 9.
    WebAPI Content Negotiation • Coremechanism of HTTP • Client specifies desired formats using Accept hearder • <<Diagram>>
  • 10.
    WebAPI Content Negotiation…cont GlobalConfiguration.Configuration.Formatters Count =4 [0]: {System.Net.Http.Formatting.JsonMediaTypeFormatter} [1]: {System.Net.Http.Formatting.XmlMediaTypeFormatter} [2]: {System.Net.Http.Formatting.FormUrlEncodedMediaTypeF ormatter} [3]: {System.Web.Http.ModelBinding.JQueryMvcFormUrlEncod edFormatter}
  • 11.
    Action Parameters • HowGet, Post, Put, Delete works • Primitive types (assumed not to be in message body) • Complex types (assumed to be in message boday) • Only Single model is allowed from message boday • <<Implementing PUT and POST by example>>
  • 12.
    Async Awaite inMVC 4.0 • What is Async and Await • Task Parallel Library • Async Controls
  • 13.
    Asycn Awit Example •<<Example Code walk through >>
  • 14.
    Async Controler • AsyncControlsbase class • <<How it’s used in MVC by Example>>