Upload
bertram-anthony
View
222
Download
3
Tags:
Embed Size (px)
Citation preview
Getting started with ASP.NET MVC
Dhananjay Kumar@debug_mode
http://debugmode.net
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
Give Away
Tweet your experience about webinar using the hashtag #Infragistics or tag @infragistics to win cool goodies from us.
I am Dhananjay Kumar
Developer Evangelist @infragistics6 times Microsoft MVP @debug_mode [email protected]://debugmode.net
ASP.NET MVC
Model
View
Controller
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
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
Controller
Controller Demo
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
View
View Demo
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
Model
Model
Application data logic
ORM
Business Logic
Model Demo
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
ViewBag and ViewData
Demo on ViewData and ViewBag
ViewBag and ViewData
TempData
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
TempData Demo
Types of Views
Views
Dynamic Views
Strongly Typed Views
Different kinds of View Demo
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.
Child Action Demo
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
Areas Demo
Q& A ?
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
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.