31
Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode http :// debugmode.net

Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Embed Size (px)

Citation preview

Page 1: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Getting started with ASP.NET MVC

Dhananjay Kumar@debug_mode

http://debugmode.net

Page 2: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Agenda Getting started with ASP.NET MVC Understanding Controllers Understanding Views Understanding Model ViewBag, ViewData, and TempData Strongly Typed and dynamic views Child Action and Partial Views Areas Database first approach Code first approach Using client side libraries like jQuery, Ignite UI

Page 3: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Give Away

Tweet your experience about webinar using the hashtag #Infragistics or tag @infragistics to win cool goodies from us.

Page 4: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

I am Dhananjay Kumar

Developer Evangelist @infragistics6 times Microsoft MVP @debug_mode [email protected]://debugmode.net

Page 5: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

ASP.NET MVC

Model

View

Controller

Page 6: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

ASP.NET MVC Clean separation of concerns

Enables or support Test Driven Development

Easy integration with client side libraries like JavaScript, jQuery, and Ignite UI

Developer has full control over the rendered HTML

Due to stateless nature and URL routing, highly optimized for search engines

Supports Authentication, authorization, configuration, compilation and deployment

Page 7: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Controller A Controller does all the actions in MVC. It handles user interactions or inputs. It passes user's data to a Model and selects a View to render on the UI.

A Controller is a class

It contains one or more methods called Actions

An Action can return a simple string or a selected View to the UI

Action takes all browser requests or user inputs

It retrieves data from the Model

It selects the View to be rendered on the UI

Page 8: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Controller

Page 9: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Controller Demo

Page 10: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

View Views are the components that display the application's user interface (UI)

It renders user interface

It contains markup to be rendered with the ViewEngine

There are two kinds of ViewEngine in MVC- Razor and ASPX engine

Controller may returns View

View renders data from the Model returned by the Controller

Controller can send data to View

Page 11: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

View

Page 12: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

View Demo

Page 13: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Model Model is a class which represents the problem domain. Model implements logic for the application data.

Model is a class

It is accessible to both the view and the controller

Views renders data from the model

Controller can pass data from model to the view

Model class contain the application logic

Model is place of the ORM or Data Access frameworks

Page 14: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Model

Model

Application data logic

ORM

Business Logic

Page 15: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Model Demo

Page 16: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Passing Data

ViewBag• dynamic object to pass data from

controller to view

ViewData• dictionary object to pass data from

controller to view

TempData• dictionary object to pass data from

one controller/action to another controller/action

Page 17: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

ViewBag and ViewData

Page 18: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Demo on ViewData and ViewBag

Page 19: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

ViewBag and ViewData

Page 20: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

TempData

Page 21: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

TempData TempData is used to pass data from one HTTP request to next HTTP request.

In other words, TempData is used to pass data from one controller to another controller or action to another action.

TempData is property of BaseController class.

TempData stores data in session object

TempData is property of ControllerBase class

To read data Typecasting and null checking is required.

Type of TempData is TempDataDictionary.

TempData works with HTTP redirection like HTTP 302/303 status code

Page 22: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

TempData Demo

Page 23: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Types of Views

Views

Dynamic Views

Strongly Typed Views

Page 24: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Different kinds of View Demo

Page 25: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Child Action Child Actions are the action methods which can be invoked within a view.

Child Actions are the action methods which can be invoked within the view

This is used to work with the data in the view, which are not related to the main action method

In ASP.NET MVC any action can be used as a child action

To use an action only as a child action and attribute it with the ChildActionOnly. It will make sure the action is not called by any user request and will only be used in the view.

Page 26: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Child Action Demo

Page 27: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Areas

A MVC application can have any number of Areas

Each Areas has its own controllers, models, and views.

Physically Areas are put under separate folders.

Areas are useful in managing big web applications

Page 28: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Areas Demo

Page 29: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Q& A ?

Page 30: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

Summary

Getting started with ASP.NET MVC Understanding Controllers Understanding Views Understanding Model ViewBag, ViewData, and TempData Strongly Typed and dynamic views Child Action and Partial Views Areas Database first approach Code first approach Using client side libraries like jQuery, Ignite UI

Page 31: Getting started with ASP.NET MVC Dhananjay Kumar @debug_mode

What Infragistics can offer you?• We welcome all of you to take advantage of a FREE 30 Day Trial by downloading

the product at: http://www.infragistics.com/products/ultimate/download

• Please reach out to us at [email protected] for any follow up questions you may have. We welcome the opportunity to assist you.