SlideShare une entreprise Scribd logo
1  sur  218
Working with
Controllers and Actions
in MVC




      Learn More @ http://www.learnnowonline.com
         Copyright © by Application Developers Training Company
Objectives
• Learn how controllers manage MVC applications
• Understand action methods and how they can
  receive input
• Explore how you can return a result from an
  action method




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Agenda
•   Introduction to Controllers
•   Using a Controller to Manage the Application
•   Controller Actions
•   Returning Action Results




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Introduction to Controllers




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
    Responds to user input




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
    Responds to user input
    Manages overall flow of application




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
    Responds to user input
    Manages overall flow of application
    Interacts with model to change state and data




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
      Responds to user input
      Manages overall flow of application
      Interacts with model to change state and data
      Selects a result to respond to user




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
      Responds to user input
      Manages overall flow of application
      Interacts with model to change state and data
      Selects a result to respond to user
• Does not itself contain UI, data, or business logic
  code




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
      Responds to user input
      Manages overall flow of application
      Interacts with model to change state and data
      Selects a result to respond to user
• Does not itself contain UI, data, or business logic
  code
• Ultimately responsible for servicing requests



                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
      Responds to user input
      Manages overall flow of application
      Interacts with model to change state and data
      Selects a result to respond to user
• Does not itself contain UI, data, or business logic
  code
• Ultimately responsible for servicing requests
    The application’s logic


                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Introduction to Controllers
• Controller is the traffic cop to keep things smooth
      Responds to user input
      Manages overall flow of application
      Interacts with model to change state and data
      Selects a result to respond to user
• Does not itself contain UI, data, or business logic
  code
• Ultimately responsible for servicing requests
    The application’s logic
• Lots of attention in MVC 3

                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application
  • Powerful but easy to use




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application
  • Powerful but easy to use
  • Implemented as .NET class with properties and
    methods




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application
  • Powerful but easy to use
  • Implemented as .NET class with properties and
    methods
  • System.Web.Mvc namespace




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application
  • Powerful but easy to use
  • Implemented as .NET class with properties and
    methods
  • System.Web.Mvc namespace
     Your controllers are likely to need very little code




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Using a Controller to Manage the
Application
  • Powerful but easy to use
  • Implemented as .NET class with properties and
    methods
  • System.Web.Mvc namespace
     Your controllers are likely to need very little code
     Routine infrastructure encapsulated in base classes




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters
• Otherwise, not recognized as controller




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters
• Otherwise, not recognized as controller
   Methods never called as action methods




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters
• Otherwise, not recognized as controller
   Methods never called as action methods
• Normally inherit from Controller class




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters
• Otherwise, not recognized as controller
   Methods never called as action methods
• Normally inherit from Controller class
   Which inherits from ControllerBase



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controllers in System.Web.Mvc
• Controller must:
   Implement IController interface
   Have a name ending in “Controller”
   Marked public, not abstract, no generic parameters
• Otherwise, not recognized as controller
   Methods never called as action methods
• Normally inherit from Controller class
   Which inherits from ControllerBase
   Which implements IController


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The IController Interface




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method
• Simple interface definition:




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method
• Simple interface definition:
      public interface IController {
         void Execute(RequestContext requestContext);
      }




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method
• Simple interface definition:
      public interface IController {
         void Execute(RequestContext requestContext);
      }




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method
• Simple interface definition:
      public interface IController {
         void Execute(RequestContext requestContext);
      }




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
The IController Interface
• IController requirement isn’t onerous
• Single purpose: find a controller and call Execute
  method
• Simple interface definition:
      public interface IController {
         void Execute(RequestContext requestContext);
      }

• When request arrives
   Routing identifies controller, calls Execute
   Passes in object with context information

               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController
     Adds controller features, such as TempData and
      ViewData




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController
     Adds controller features, such as TempData and
      ViewData
     Execute method creates ControllerContext object




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController
      Adds controller features, such as TempData and
       ViewData
      Execute method creates ControllerContext object
  • Still pretty lightweight




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController
      Adds controller features, such as TempData and
       ViewData
      Execute method creates ControllerContext object
  • Still pretty lightweight
      Relatively little added functionality




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
The ControllerBase Abstract Base
Class
  • Implements IController
      Adds controller features, such as TempData and
       ViewData
      Execute method creates ControllerContext object
  • Still pretty lightweight
      Relatively little added functionality
      Could build Web site with either IController or
       ControllerBase



              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
The Controller Class




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController
• Added features include




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController
• Added features include
   Action methods




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController
• Added features include
   Action methods
   Action results




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController
• Added features include
   Action methods
   Action results
   Filters




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The Controller Class
• Rich implementation of controller infrastructure
• Inherits from ControllerBase
   So indirectly implements IController
• Added features include
   Action methods
   Action results
   Filters
• Normally should implement your controllers
  using Controller

             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The MVC Request Processing




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
   IIS, ASP.NET, MVC collaboration




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
    IIS, ASP.NET, MVC collaboration

Request




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
    IIS, ASP.NET, MVC collaboration

Request
          HTTP




                 Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
    IIS, ASP.NET, MVC collaboration

Request
          HTTP

          Routing Engine            Controller Factory                     Controller




              View                    Action Method                     Action Invoker




                  Learn More @ http://www.learnnowonline.com
                      Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
    IIS, ASP.NET, MVC collaboration

Request
          HTTP

          Routing Engine            Controller Factory                     Controller




              View                    Action Method                     Action Invoker



                                                                                HTTP

                  Learn More @ http://www.learnnowonline.com
                      Copyright © by Application Developers Training Company
The MVC Request Processing
• Response process to every user request
    IIS, ASP.NET, MVC collaboration

Request
          HTTP

          Routing Engine            Controller Factory                     Controller




              View                    Action Method                     Action Invoker


                                                                                         Response
                                                                                HTTP

                  Learn More @ http://www.learnnowonline.com
                      Copyright © by Application Developers Training Company
Action Method Selection




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use
   Action name may be different from method name




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use
   Action name may be different from method name
• Starts by getting action portion of route
  {controller}/{action}/{id}




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use
   Action name may be different from method name
• Starts by getting action portion of route
  {controller}/{action}/{id}
   Default action is “Index”



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use
   Action name may be different from method name
• Starts by getting action portion of route
  {controller}/{action}/{id}
   Default action is “Index”
• Then map action name to controller method

             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Selection
• Job of the action invoker
• More complicated than initially appears
   Multiple overloaded methods with same name
   Decorated with attributes that control use
   Action name may be different from method name
• Starts by getting action portion of route
  {controller}/{action}/{id}
   Default action is “Index”
• Then map action name to controller method
   Simplest: one method with that action name
             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Qualifications




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method
   Cannot be a special method




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method
   Cannot be a special method
   Cannot have a NonAction attribute




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method
   Cannot be a special method
   Cannot have a NonAction attribute
• Action invoker uses reflection to find candidates



                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method
   Cannot be a special method
   Cannot have a NonAction attribute
• Action invoker uses reflection to find candidates
   All methods with same action name


                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Qualifications
• Method must meet requirements to be action
  method:
   Public and not static or Shared
   Cannot be defined on System.Object or Controller
     o   i.e., ToString() could not be an action method
   Cannot be a special method
   Cannot have a NonAction attribute
• Action invoker uses reflection to find candidates
   All methods with same action name
   But method attributes can make this murky with
    multiple candidates
                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
ActionName Attribute




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
ActionName Attribute
• Normal convention is for controller method name
  to be same as action name




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ActionName Attribute
• Normal convention is for controller method name
  to be same as action name
• Can give it a different action name




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ActionName Attribute
• Normal convention is for controller method name
  to be same as action name
• Can give it a different action name
   Action name that is not a legal language name




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ActionName Attribute
• Normal convention is for controller method name
  to be same as action name
• Can give it a different action name
   Action name that is not a legal language name
   Use an MVC component name as action name




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ActionName Attribute
• Normal convention is for controller method name
  to be same as action name
• Can give it a different action name
   Action name that is not a legal language name
   Use an MVC component name as action name
   Different naming standards




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ActionMethodSelector Attribute




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method




               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method
      o   Return false, removed from list




               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method
      o   Return false, removed from list

• Implementations



               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method
      o   Return false, removed from list

• Implementations
    NonAction attribute



               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method
      o   Return false, removed from list

• Implementations
    NonAction attribute
    AcceptVerbs attribute

               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
ActionMethodSelector Attribute
• Now action invoker has list of all matching action
  names
• Next examines ActionMethodSelector attributes
    Control what conditions a method should be used for a
     request
    Single method: IsValidForRequest
      o   Executes on each candidate action method
      o   Return false, removed from list

• Implementations
    NonAction attribute
    AcceptVerbs attribute
    HttpDelete, HttpGet, HttpPost, HttpPut
               Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Controller Actions




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing
   Generate output




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing
   Generate output
     o   Select a view




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing
   Generate output
     o   Select a view
     o   Write output directly to page




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing
   Generate output
     o   Select a view
     o   Write output directly to page
     o   Raw data to browser




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Controller Actions
• Once invoked, action method does its job
   Receive and process input
   Perform processing
   Generate output
     o   Select a view
     o   Write output directly to page
     o   Raw data to browser
     o   Do nothing




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Method Input




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
   Environment




             Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
   Environment
   Operating system




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
   Environment
   Operating system
   Nature of user request




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters
     Many others




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters
     Many others
• Three broad sources for action method




                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters
     Many others
• Three broad sources for action method
   Context objects



                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters
     Many others
• Three broad sources for action method
   Context objects
   Method parameters


                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Action Method Input
• Most methods need data to do work
• Can come from a variety of sources
     Environment
     Operating system
     Nature of user request
     Direct parameters
     Many others
• Three broad sources for action method
   Context objects
   Method parameters
   Model bindings
                Learn More @ http://www.learnnowonline.com
                   Copyright © by Application Developers Training Company
Context Object Input




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
   HTTP headers




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
   HTTP headers
   User information




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
   HTTP headers
   User information
   Browser and capability information




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
     HTTP headers
     User information
     Browser and capability information
     User’s IP address




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
     HTTP headers
     User information
     Browser and capability information
     User’s IP address
     Authentication information




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
Context Object Input
• Web requests come loaded with information
     HTTP headers
     User information
     Browser and capability information
     User’s IP address
     Authentication information
• Information available through context objects




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
Parameter Input




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form
  2. RouteData.Values




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form
  2. RouteData.Values
  3. Request.QueryString




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form
  2. RouteData.Values
  3. Request.QueryString
• Matches solely by name in order


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form
  2. RouteData.Values
  3. Request.QueryString
• Matches solely by name in order
   Once it finds a match it stops searching


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Parameter Input
• Specialized input customized for method
• MVC takes care of populating values
• Action invoker examines context objects for
  parameter values and uses model binder
  1. Request.Form
  2. RouteData.Values
  3. Request.QueryString
• Matches solely by name in order
   Once it finds a match it stops searching
   Have to coordinate names to avoid duplicate names
            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Model Bindings




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Model Bindings
• Model encapsulates data and business rules




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Model Bindings
• Model encapsulates data and business rules
   Use directly in controllers and views




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Model Bindings
• Model encapsulates data and business rules
   Use directly in controllers and views
   Built-in features to make easy




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Model Bindings
• Model encapsulates data and business rules
   Use directly in controllers and views
   Built-in features to make easy
   Automatic data scaffolding




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Session State




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available
• SessionStateBehavior enumeration




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available
• SessionStateBehavior enumeration
   Default




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available
• SessionStateBehavior enumeration
   Default
   Disabled




               Learn More @ http://www.learnnowonline.com
                  Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available
• SessionStateBehavior enumeration
   Default
   Disabled
   ReadOnly




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Controller Session State
• SessionState attribute
   Control how and whether controller uses session state
   MVC uses session state by default, if available
• SessionStateBehavior enumeration
     Default
     Disabled
     ReadOnly
     Required




             Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Returning Action Results




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses
• Three broad types of results




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses
• Three broad types of results
   HTML




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses
• Three broad types of results
   HTML
   Redirect somewhere else



            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses
• Three broad types of results
   HTML
   Redirect somewhere else
   Page data


            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Action Results
• Action method follows a normal process
   Receives request and data
   Process the request
   Generates response
• Many possible responses
• Three broad types of results
   HTML
   Redirect somewhere else
   Page data
• All options based on ActionResult
            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Result




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Action Result
• ActionResult base class




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Action Result
• ActionResult base class
     public abstract class ActionResult {
        public abstract void ExecuteResult(ControllerContext context);
     }




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Result
• ActionResult base class
     public abstract class ActionResult {
        public abstract void ExecuteResult(ControllerContext context);
     }




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
Action Result
• ActionResult base class
     public abstract class ActionResult {
        public abstract void ExecuteResult(ControllerContext context);
     }

• ExecuteResult receives context information
• Takes care of low-level work of generating a
  response




                Learn More @ http://www.learnnowonline.com
                    Copyright © by Application Developers Training Company
ActionResult Types




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
ActionResult Types
Type                          Helper Method                   Description
ContentResult                 Content()                       Raw text data
EmptyResult                   --                              Returns nothing
FileResult                    File()                          Base class to send file
HttpNotFoundResult            HttpNotFound()                  Returns HTTP 404
HttpStatusCodeResult          --                              Returns any HTTP status
HttpUnauthorizedResult        --                              Returns HTTP 401
JavaScriptResult              JavaScript()                    Returns and executes script
JsonResult                    Json()                          JavaScript Object Notation
PartialViewResult             PartialView()                   HTML snippet
RedirectResult                Redirect()                      Redirect to URL
RedirectToRouteResult         RedirectToRoute()               Redirect to MVC route or action
ViewResult                    RedirectToAction()
                              View()                          Full HTML page
                    Learn More @ http://www.learnnowonline.com
                        Copyright © by Application Developers Training Company
Passing Data to the View




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
   Different faces of the same feature




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
   Different faces of the same feature
   A bit like ASP.NET Session object




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
   Different faces of the same feature
   A bit like ASP.NET Session object
   Exposes ViewDataDictionary




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
     Different faces of the same feature
     A bit like ASP.NET Session object
     Exposes ViewDataDictionary
     But ViewData/ViewBag disappear after view rendered




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
     Different faces of the same feature
     A bit like ASP.NET Session object
     Exposes ViewDataDictionary
     But ViewData/ViewBag disappear after view rendered
     Session lasts for the user session




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
     Different faces of the same feature
     A bit like ASP.NET Session object
     Exposes ViewDataDictionary
     But ViewData/ViewBag disappear after view rendered
     Session lasts for the user session
• ViewData is loosely typed




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
     Different faces of the same feature
     A bit like ASP.NET Session object
     Exposes ViewDataDictionary
     But ViewData/ViewBag disappear after view rendered
     Session lasts for the user session
• ViewData is loosely typed
• ViewBag is strongly typed



              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Passing Data to the View
• Use either ViewData or ViewBag
     Different faces of the same feature
     A bit like ASP.NET Session object
     Exposes ViewDataDictionary
     But ViewData/ViewBag disappear after view rendered
     Session lasts for the user session
• ViewData is loosely typed
• ViewBag is strongly typed
   Uses dynamic language feature of C# and VB


              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
ViewData and ViewBag




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings
• Keep in mind that they are same feature, but
  different




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings
• Keep in mind that they are same feature, but
  different
   Can mix and match in one action method/view




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings
• Keep in mind that they are same feature, but
  different
   Can mix and match in one action method/view
   Get the same result either way




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings
• Keep in mind that they are same feature, but
  different
   Can mix and match in one action method/view
   Get the same result either way
   Generally should use ViewBag




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
ViewData and ViewBag
• Not limited to passing strings
• Keep in mind that they are same feature, but
  different
    Can mix and match in one action method/view
    Get the same result either way
    Generally should use ViewBag
• But in VB, using in controller requires setting
  Option Strict Off



             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Returning Text Data: ContentResult




          Learn More @ http://www.learnnowonline.com
             Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format
    But browsers can deal with variety of formats




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format
    But browsers can deal with variety of formats
 • Use a ContentResult for other formats




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format
    But browsers can deal with variety of formats
 • Use a ContentResult for other formats
    Content helper method




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format
    But browsers can deal with variety of formats
 • Use a ContentResult for other formats
    Content helper method
    Specify content as string




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Returning Text Data: ContentResult
 • HTML is dominant data format
    But browsers can deal with variety of formats
 • Use a ContentResult for other formats
    Content helper method
    Specify content as string
    Optionally specify type, such as text/xml




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Implicit Action Results




         Learn More @ http://www.learnnowonline.com
            Copyright © by Application Developers Training Company
Implicit Action Results
• Return text and don’t need to specify type




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Implicit Action Results
• Return text and don’t need to specify type
• If type is not string, calls ToString method with
  InvariantCulture setting




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Implicit Action Results
• Return text and don’t need to specify type
• If type is not string, calls ToString method with
  InvariantCulture setting
    Wraps in ContentResult object




              Learn More @ http://www.learnnowonline.com
                 Copyright © by Application Developers Training Company
Missing Resource:




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Missing Resource:
• Useful to indicate that requested resource is not
  available




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Missing Resource:
• Useful to indicate that requested resource is not
  available
   User hacks a URL




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Missing Resource:
• Useful to indicate that requested resource is not
  available
   User hacks a URL
• Returns HTTP 404 status code




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Missing Resource:
• Useful to indicate that requested resource is not
  available
   User hacks a URL
• Returns HTTP 404 status code
   Can mask an exception that an attacker could
    otherwise use




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Return any HTTP Status Code:




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Return any HTTP Status Code:
• More flexible than HttpNotFoundResult




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Return any HTTP Status Code:
• More flexible than HttpNotFoundResult
• Can specify any HTTP status code




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Return any HTTP Status Code:
• More flexible than HttpNotFoundResult
• Can specify any HTTP status code
   Optional description




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods




        Learn More @ http://www.learnnowonline.com
           Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods




            Learn More @ http://www.learnnowonline.com
               Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types
   RedirectPermanent method




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types
   RedirectPermanent method
   RedirectToRoutePermanent method




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types
   RedirectPermanent method
   RedirectToRoutePermanent method
   RedirectToActionPermanent method




             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types
   RedirectPermanent method
   RedirectToRoutePermanent method
   RedirectToActionPermanent method
• Make easy to manage permanent redirections


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Redirection Methods
• Methods on the Controller class
• Return instances of redirection action methods
   Permanent property set to true
• Types
   RedirectPermanent method
   RedirectToRoutePermanent method
   RedirectToActionPermanent method
• Make easy to manage permanent redirections
   HTTP 301 status code


             Learn More @ http://www.learnnowonline.com
                Copyright © by Application Developers Training Company
Learn More!




       Learn More @ http://www.learnnowonline.com
          Copyright © by Application Developers Training Company
Learn More!
• This is an excerpt from a larger course. Visit
  www.learnnowonline.com for the full details!




           Learn More @ http://www.learnnowonline.com
              Copyright © by Application Developers Training Company

Contenu connexe

Tendances

Eliminate Risks in SOA Implementation & Support
Eliminate Risks in SOA Implementation & SupportEliminate Risks in SOA Implementation & Support
Eliminate Risks in SOA Implementation & SupportSuneraTech
 
Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value Srinivasu Chakravarthula
 
Appmotives - Software Testing As Service
Appmotives - Software Testing As ServiceAppmotives - Software Testing As Service
Appmotives - Software Testing As ServiceKalyan Paluri
 
The Powerful and Comprehensive API for Mobile App Development and Testing
The Powerful and Comprehensive API for Mobile App Development and TestingThe Powerful and Comprehensive API for Mobile App Development and Testing
The Powerful and Comprehensive API for Mobile App Development and TestingBitbar
 
Atagg 2015 Test automation and effective continuous integration
Atagg 2015 Test automation and effective continuous integrationAtagg 2015 Test automation and effective continuous integration
Atagg 2015 Test automation and effective continuous integrationAgile Testing Alliance
 
Helping Organizations Realize the Value of DevOps with Continuous Software De...
Helping Organizations Realize the Value of DevOps with Continuous Software De...Helping Organizations Realize the Value of DevOps with Continuous Software De...
Helping Organizations Realize the Value of DevOps with Continuous Software De...IBM UrbanCode Products
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsKazuaki Matsuo
 
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...AppDynamics
 
DevBeat 2013 IBM Master Class presentation
DevBeat 2013 IBM Master Class presentationDevBeat 2013 IBM Master Class presentation
DevBeat 2013 IBM Master Class presentationLeigh Williamson
 
Test Automation Framework Online Training by QuontraSolutions
Test Automation Framework Online Training by QuontraSolutionsTest Automation Framework Online Training by QuontraSolutions
Test Automation Framework Online Training by QuontraSolutionsQuontra Solutions
 
15.3 student guide web application tool time overviewtodays c
15.3 student guide web application tool time overviewtodays c15.3 student guide web application tool time overviewtodays c
15.3 student guide web application tool time overviewtodays cUMAR48665
 
Test Automation Frameworks Using Selenium | Edureka
Test Automation Frameworks Using Selenium | EdurekaTest Automation Frameworks Using Selenium | Edureka
Test Automation Frameworks Using Selenium | EdurekaEdureka!
 
Performance Testing Insights
Performance Testing InsightsPerformance Testing Insights
Performance Testing InsightsDeepu S Nath
 
Top 10 Automation Testing Tools in 2020
Top 10 Automation Testing Tools in 2020Top 10 Automation Testing Tools in 2020
Top 10 Automation Testing Tools in 2020Alaina Carter
 
How To Sell Into Insurance with Perfecto
How To Sell Into Insurance with PerfectoHow To Sell Into Insurance with Perfecto
How To Sell Into Insurance with PerfectoLizzy Guido (she/her)
 
API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...SlideTeam
 
Building Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformBuilding Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformAndrew Ferrier
 

Tendances (18)

Eliminate Risks in SOA Implementation & Support
Eliminate Risks in SOA Implementation & SupportEliminate Risks in SOA Implementation & Support
Eliminate Risks in SOA Implementation & Support
 
Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value Accessibility testing technology, human touch and value
Accessibility testing technology, human touch and value
 
Appmotives - Software Testing As Service
Appmotives - Software Testing As ServiceAppmotives - Software Testing As Service
Appmotives - Software Testing As Service
 
The Powerful and Comprehensive API for Mobile App Development and Testing
The Powerful and Comprehensive API for Mobile App Development and TestingThe Powerful and Comprehensive API for Mobile App Development and Testing
The Powerful and Comprehensive API for Mobile App Development and Testing
 
Atagg 2015 Test automation and effective continuous integration
Atagg 2015 Test automation and effective continuous integrationAtagg 2015 Test automation and effective continuous integration
Atagg 2015 Test automation and effective continuous integration
 
Helping Organizations Realize the Value of DevOps with Continuous Software De...
Helping Organizations Realize the Value of DevOps with Continuous Software De...Helping Organizations Realize the Value of DevOps with Continuous Software De...
Helping Organizations Realize the Value of DevOps with Continuous Software De...
 
Uncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applicationsUncovering breaking changes behind UI on mobile applications
Uncovering breaking changes behind UI on mobile applications
 
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...
How Financial Engines Drives Business Outcomes Using AppDynamics Analytics - ...
 
DevBeat 2013 IBM Master Class presentation
DevBeat 2013 IBM Master Class presentationDevBeat 2013 IBM Master Class presentation
DevBeat 2013 IBM Master Class presentation
 
Test Automation Framework Online Training by QuontraSolutions
Test Automation Framework Online Training by QuontraSolutionsTest Automation Framework Online Training by QuontraSolutions
Test Automation Framework Online Training by QuontraSolutions
 
15.3 student guide web application tool time overviewtodays c
15.3 student guide web application tool time overviewtodays c15.3 student guide web application tool time overviewtodays c
15.3 student guide web application tool time overviewtodays c
 
Test Automation Frameworks Using Selenium | Edureka
Test Automation Frameworks Using Selenium | EdurekaTest Automation Frameworks Using Selenium | Edureka
Test Automation Frameworks Using Selenium | Edureka
 
Performance Testing Insights
Performance Testing InsightsPerformance Testing Insights
Performance Testing Insights
 
Top 10 Automation Testing Tools in 2020
Top 10 Automation Testing Tools in 2020Top 10 Automation Testing Tools in 2020
Top 10 Automation Testing Tools in 2020
 
How To Sell Into Insurance with Perfecto
How To Sell Into Insurance with PerfectoHow To Sell Into Insurance with Perfecto
How To Sell Into Insurance with Perfecto
 
API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...API Integration For Building Software Applications Powerpoint Presentation Sl...
API Integration For Building Software Applications Powerpoint Presentation Sl...
 
Building Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst PlatformBuilding Effective and Rapid Applications with IBM MobileFirst Platform
Building Effective and Rapid Applications with IBM MobileFirst Platform
 
ansari
ansariansari
ansari
 

En vedette

Electronic controllers presentation
Electronic controllers presentationElectronic controllers presentation
Electronic controllers presentationAkshay Dhole
 
Pid controllers
Pid controllersPid controllers
Pid controllersmilind1076
 
PID Controller
PID ControllerPID Controller
PID Controllersaishah72
 
Proportional-Derivative-Integral (PID) Control
Proportional-Derivative-Integral (PID) ControlProportional-Derivative-Integral (PID) Control
Proportional-Derivative-Integral (PID) Controlguest9006ab
 
Controller ppt
Controller pptController ppt
Controller pptgourav0077
 
Traffic light controller
Traffic light controllerTraffic light controller
Traffic light controllerRkrishna Mishra
 
Basic types of facts controllers
Basic types of facts controllersBasic types of facts controllers
Basic types of facts controllersAyyarao T S L V
 

En vedette (13)

Electronic controllers presentation
Electronic controllers presentationElectronic controllers presentation
Electronic controllers presentation
 
Time Response
Time ResponseTime Response
Time Response
 
Class 23 electronic controllers
Class 23   electronic controllersClass 23   electronic controllers
Class 23 electronic controllers
 
Pid controllers
Pid controllersPid controllers
Pid controllers
 
PID Controller
PID ControllerPID Controller
PID Controller
 
Block Diagram For Control Systems.
Block Diagram For Control Systems.Block Diagram For Control Systems.
Block Diagram For Control Systems.
 
p i d controller
p i d controllerp i d controller
p i d controller
 
Proportional-Derivative-Integral (PID) Control
Proportional-Derivative-Integral (PID) ControlProportional-Derivative-Integral (PID) Control
Proportional-Derivative-Integral (PID) Control
 
Controller ppt
Controller pptController ppt
Controller ppt
 
Traffic light controller
Traffic light controllerTraffic light controller
Traffic light controller
 
Basic types of facts controllers
Basic types of facts controllersBasic types of facts controllers
Basic types of facts controllers
 
Active Directory Training
Active Directory TrainingActive Directory Training
Active Directory Training
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similaire à MVC Controllers Actions Guide

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCLearnNowOnline
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5LearnNowOnline
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5LearnNowOnline
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User InterfaceLearnNowOnline
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCLearnNowOnline
 
#1922 rest-push2 ap-im-v6
#1922 rest-push2 ap-im-v6#1922 rest-push2 ap-im-v6
#1922 rest-push2 ap-im-v6Jack Carnes
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsLearnNowOnline
 
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...eG Innovations
 
API Economy - Cuomo
API Economy - Cuomo API Economy - Cuomo
API Economy - Cuomo Prolifics
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data TypesLearnNowOnline
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow controlLearnNowOnline
 
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...eG Innovations
 
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...Hamida Rebai Trabelsi
 
My Application is Slow | Best Practices for Troubleshooting and Prevention
My Application is Slow | Best Practices for Troubleshooting and PreventionMy Application is Slow | Best Practices for Troubleshooting and Prevention
My Application is Slow | Best Practices for Troubleshooting and PreventioneG Innovations
 
Developers Are Users, Too
Developers Are Users, TooDevelopers Are Users, Too
Developers Are Users, TooVMware Tanzu
 

Similaire à MVC Controllers Actions Guide (20)

Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
What's new in Silverlight 5
What's new in Silverlight 5What's new in Silverlight 5
What's new in Silverlight 5
 
Web API HTTP Pipeline
Web API HTTP PipelineWeb API HTTP Pipeline
Web API HTTP Pipeline
 
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5Building Windows 8 Metro Style Applications Using JavaScript and HTML5
Building Windows 8 Metro Style Applications Using JavaScript and HTML5
 
Creating a User Interface
Creating a User InterfaceCreating a User Interface
Creating a User Interface
 
KnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVCKnockOutJS with ASP.NET MVC
KnockOutJS with ASP.NET MVC
 
SQL Server: Security
SQL Server: SecuritySQL Server: Security
SQL Server: Security
 
#1922 rest-push2 ap-im-v6
#1922 rest-push2 ap-im-v6#1922 rest-push2 ap-im-v6
#1922 rest-push2 ap-im-v6
 
JavaScript: Operators and Expressions
JavaScript: Operators and ExpressionsJavaScript: Operators and Expressions
JavaScript: Operators and Expressions
 
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
 
API Economy - Cuomo
API Economy - Cuomo API Economy - Cuomo
API Economy - Cuomo
 
.NET Variables and Data Types
.NET Variables and Data Types.NET Variables and Data Types
.NET Variables and Data Types
 
.Net branching and flow control
.Net branching and flow control.Net branching and flow control
.Net branching and flow control
 
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
Best Practices for Troubleshooting Slow Citrix Logon and Ensuring Excellent U...
 
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...
Azure Spring Clean 2024 event - Azure API Management: Architecting for Perfor...
 
A perspective on web testing
A perspective on web testingA perspective on web testing
A perspective on web testing
 
A perspective on web testing
A perspective on web testingA perspective on web testing
A perspective on web testing
 
My Application is Slow | Best Practices for Troubleshooting and Prevention
My Application is Slow | Best Practices for Troubleshooting and PreventionMy Application is Slow | Best Practices for Troubleshooting and Prevention
My Application is Slow | Best Practices for Troubleshooting and Prevention
 
WPF Binding
WPF BindingWPF Binding
WPF Binding
 
Developers Are Users, Too
Developers Are Users, TooDevelopers Are Users, Too
Developers Are Users, Too
 

Plus de LearnNowOnline

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesLearnNowOnline
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionLearnNowOnline
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDELearnNowOnline
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingLearnNowOnline
 
Asynchronous Programming
Asynchronous ProgrammingAsynchronous Programming
Asynchronous ProgrammingLearnNowOnline
 
WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with DataLearnNowOnline
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniquesLearnNowOnline
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptLearnNowOnline
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document ManagementLearnNowOnline
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathLearnNowOnline
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collectionsLearnNowOnline
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programmingLearnNowOnline
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignLearnNowOnline
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity FrameworkLearnNowOnline
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET FrameworkLearnNowOnline
 

Plus de LearnNowOnline (20)

Windows 8: Shapes and Geometries
Windows 8: Shapes and GeometriesWindows 8: Shapes and Geometries
Windows 8: Shapes and Geometries
 
SQL: Permissions and Data Protection
SQL: Permissions and Data ProtectionSQL: Permissions and Data Protection
SQL: Permissions and Data Protection
 
New in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDENew in the Visual Studio 2012 IDE
New in the Visual Studio 2012 IDE
 
Attributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programmingAttributes, reflection, and dynamic programming
Attributes, reflection, and dynamic programming
 
Asynchronous Programming
Asynchronous ProgrammingAsynchronous Programming
Asynchronous Programming
 
WPF: Working with Data
WPF: Working with DataWPF: Working with Data
WPF: Working with Data
 
A tour of SQL Server
A tour of SQL ServerA tour of SQL Server
A tour of SQL Server
 
Introducing LINQ
Introducing LINQIntroducing LINQ
Introducing LINQ
 
Generics
GenericsGenerics
Generics
 
Object oriented techniques
Object oriented techniquesObject oriented techniques
Object oriented techniques
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
SharePoint Document Management
SharePoint Document ManagementSharePoint Document Management
SharePoint Document Management
 
SharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPathSharePoint: Introduction to InfoPath
SharePoint: Introduction to InfoPath
 
Managing site collections
Managing site collectionsManaging site collections
Managing site collections
 
Web API Basics
Web API BasicsWeb API Basics
Web API Basics
 
Sql 2012 development and programming
Sql 2012  development and programmingSql 2012  development and programming
Sql 2012 development and programming
 
Expression Blend Motion & Interaction Design
Expression Blend Motion & Interaction DesignExpression Blend Motion & Interaction Design
Expression Blend Motion & Interaction Design
 
The Entity Data Model
The Entity Data ModelThe Entity Data Model
The Entity Data Model
 
Introducing the Entity Framework
Introducing the Entity FrameworkIntroducing the Entity Framework
Introducing the Entity Framework
 
Using The .NET Framework
Using The .NET FrameworkUsing The .NET Framework
Using The .NET Framework
 

Dernier

WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneUiPathCommunity
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Nikki Chapple
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Dernier (20)

WomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyoneWomenInAutomation2024: AI and Automation for eveyone
WomenInAutomation2024: AI and Automation for eveyone
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
Microsoft 365 Copilot: How to boost your productivity with AI – Part two: Dat...
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

MVC Controllers Actions Guide

  • 1. Working with Controllers and Actions in MVC Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 2. Objectives • Learn how controllers manage MVC applications • Understand action methods and how they can receive input • Explore how you can return a result from an action method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 3. Agenda • Introduction to Controllers • Using a Controller to Manage the Application • Controller Actions • Returning Action Results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 4. Introduction to Controllers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 5. Introduction to Controllers • Controller is the traffic cop to keep things smooth Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 6. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 7. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 8. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 9. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data  Selects a result to respond to user Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 10. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data  Selects a result to respond to user • Does not itself contain UI, data, or business logic code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 11. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data  Selects a result to respond to user • Does not itself contain UI, data, or business logic code • Ultimately responsible for servicing requests Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 12. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data  Selects a result to respond to user • Does not itself contain UI, data, or business logic code • Ultimately responsible for servicing requests  The application’s logic Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 13. Introduction to Controllers • Controller is the traffic cop to keep things smooth  Responds to user input  Manages overall flow of application  Interacts with model to change state and data  Selects a result to respond to user • Does not itself contain UI, data, or business logic code • Ultimately responsible for servicing requests  The application’s logic • Lots of attention in MVC 3 Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 14. Using a Controller to Manage the Application Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 15. Using a Controller to Manage the Application • Powerful but easy to use Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 16. Using a Controller to Manage the Application • Powerful but easy to use • Implemented as .NET class with properties and methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 17. Using a Controller to Manage the Application • Powerful but easy to use • Implemented as .NET class with properties and methods • System.Web.Mvc namespace Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 18. Using a Controller to Manage the Application • Powerful but easy to use • Implemented as .NET class with properties and methods • System.Web.Mvc namespace  Your controllers are likely to need very little code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 19. Using a Controller to Manage the Application • Powerful but easy to use • Implemented as .NET class with properties and methods • System.Web.Mvc namespace  Your controllers are likely to need very little code  Routine infrastructure encapsulated in base classes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 20. Controllers in System.Web.Mvc Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 21. Controllers in System.Web.Mvc • Controller must: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 22. Controllers in System.Web.Mvc • Controller must:  Implement IController interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 23. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller” Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 24. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 25. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters • Otherwise, not recognized as controller Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 26. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters • Otherwise, not recognized as controller  Methods never called as action methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 27. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters • Otherwise, not recognized as controller  Methods never called as action methods • Normally inherit from Controller class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 28. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters • Otherwise, not recognized as controller  Methods never called as action methods • Normally inherit from Controller class  Which inherits from ControllerBase Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 29. Controllers in System.Web.Mvc • Controller must:  Implement IController interface  Have a name ending in “Controller”  Marked public, not abstract, no generic parameters • Otherwise, not recognized as controller  Methods never called as action methods • Normally inherit from Controller class  Which inherits from ControllerBase  Which implements IController Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 30. The IController Interface Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 31. The IController Interface • IController requirement isn’t onerous Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 32. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 33. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method • Simple interface definition: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 34. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method • Simple interface definition: public interface IController { void Execute(RequestContext requestContext); } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 35. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method • Simple interface definition: public interface IController { void Execute(RequestContext requestContext); } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 36. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method • Simple interface definition: public interface IController { void Execute(RequestContext requestContext); } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 37. The IController Interface • IController requirement isn’t onerous • Single purpose: find a controller and call Execute method • Simple interface definition: public interface IController { void Execute(RequestContext requestContext); } • When request arrives  Routing identifies controller, calls Execute  Passes in object with context information Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 38. The ControllerBase Abstract Base Class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 39. The ControllerBase Abstract Base Class • Implements IController Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 40. The ControllerBase Abstract Base Class • Implements IController  Adds controller features, such as TempData and ViewData Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 41. The ControllerBase Abstract Base Class • Implements IController  Adds controller features, such as TempData and ViewData  Execute method creates ControllerContext object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 42. The ControllerBase Abstract Base Class • Implements IController  Adds controller features, such as TempData and ViewData  Execute method creates ControllerContext object • Still pretty lightweight Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 43. The ControllerBase Abstract Base Class • Implements IController  Adds controller features, such as TempData and ViewData  Execute method creates ControllerContext object • Still pretty lightweight  Relatively little added functionality Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 44. The ControllerBase Abstract Base Class • Implements IController  Adds controller features, such as TempData and ViewData  Execute method creates ControllerContext object • Still pretty lightweight  Relatively little added functionality  Could build Web site with either IController or ControllerBase Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 45. The Controller Class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 46. The Controller Class • Rich implementation of controller infrastructure Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 47. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 48. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 49. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController • Added features include Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 50. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController • Added features include  Action methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 51. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController • Added features include  Action methods  Action results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 52. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController • Added features include  Action methods  Action results  Filters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 53. The Controller Class • Rich implementation of controller infrastructure • Inherits from ControllerBase  So indirectly implements IController • Added features include  Action methods  Action results  Filters • Normally should implement your controllers using Controller Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 54. The MVC Request Processing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 55. The MVC Request Processing • Response process to every user request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 56. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 57. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 58. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Request HTTP Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 59. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Request HTTP Routing Engine Controller Factory Controller View Action Method Action Invoker Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 60. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Request HTTP Routing Engine Controller Factory Controller View Action Method Action Invoker HTTP Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 61. The MVC Request Processing • Response process to every user request  IIS, ASP.NET, MVC collaboration Request HTTP Routing Engine Controller Factory Controller View Action Method Action Invoker Response HTTP Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 62. Action Method Selection Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 63. Action Method Selection • Job of the action invoker Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 64. Action Method Selection • Job of the action invoker • More complicated than initially appears Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 65. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 66. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 67. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use  Action name may be different from method name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 68. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use  Action name may be different from method name • Starts by getting action portion of route {controller}/{action}/{id} Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 69. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use  Action name may be different from method name • Starts by getting action portion of route {controller}/{action}/{id}  Default action is “Index” Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 70. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use  Action name may be different from method name • Starts by getting action portion of route {controller}/{action}/{id}  Default action is “Index” • Then map action name to controller method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 71. Action Method Selection • Job of the action invoker • More complicated than initially appears  Multiple overloaded methods with same name  Decorated with attributes that control use  Action name may be different from method name • Starts by getting action portion of route {controller}/{action}/{id}  Default action is “Index” • Then map action name to controller method  Simplest: one method with that action name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 72. Action Method Qualifications Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 73. Action Method Qualifications • Method must meet requirements to be action method: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 74. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 75. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 76. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 77. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method  Cannot be a special method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 78. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method  Cannot be a special method  Cannot have a NonAction attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 79. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method  Cannot be a special method  Cannot have a NonAction attribute • Action invoker uses reflection to find candidates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 80. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method  Cannot be a special method  Cannot have a NonAction attribute • Action invoker uses reflection to find candidates  All methods with same action name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 81. Action Method Qualifications • Method must meet requirements to be action method:  Public and not static or Shared  Cannot be defined on System.Object or Controller o i.e., ToString() could not be an action method  Cannot be a special method  Cannot have a NonAction attribute • Action invoker uses reflection to find candidates  All methods with same action name  But method attributes can make this murky with multiple candidates Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 82. ActionName Attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 83. ActionName Attribute • Normal convention is for controller method name to be same as action name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 84. ActionName Attribute • Normal convention is for controller method name to be same as action name • Can give it a different action name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 85. ActionName Attribute • Normal convention is for controller method name to be same as action name • Can give it a different action name  Action name that is not a legal language name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 86. ActionName Attribute • Normal convention is for controller method name to be same as action name • Can give it a different action name  Action name that is not a legal language name  Use an MVC component name as action name Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 87. ActionName Attribute • Normal convention is for controller method name to be same as action name • Can give it a different action name  Action name that is not a legal language name  Use an MVC component name as action name  Different naming standards Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 88. ActionMethodSelector Attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 89. ActionMethodSelector Attribute • Now action invoker has list of all matching action names Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 90. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 91. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 92. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 93. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 94. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method o Return false, removed from list Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 95. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method o Return false, removed from list • Implementations Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 96. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method o Return false, removed from list • Implementations  NonAction attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 97. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method o Return false, removed from list • Implementations  NonAction attribute  AcceptVerbs attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 98. ActionMethodSelector Attribute • Now action invoker has list of all matching action names • Next examines ActionMethodSelector attributes  Control what conditions a method should be used for a request  Single method: IsValidForRequest o Executes on each candidate action method o Return false, removed from list • Implementations  NonAction attribute  AcceptVerbs attribute  HttpDelete, HttpGet, HttpPost, HttpPut Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 99. Controller Actions Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 100. Controller Actions • Once invoked, action method does its job Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 101. Controller Actions • Once invoked, action method does its job  Receive and process input Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 102. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 103. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing  Generate output Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 104. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing  Generate output o Select a view Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 105. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing  Generate output o Select a view o Write output directly to page Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 106. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing  Generate output o Select a view o Write output directly to page o Raw data to browser Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 107. Controller Actions • Once invoked, action method does its job  Receive and process input  Perform processing  Generate output o Select a view o Write output directly to page o Raw data to browser o Do nothing Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 108. Action Method Input Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 109. Action Method Input • Most methods need data to do work Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 110. Action Method Input • Most methods need data to do work • Can come from a variety of sources Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 111. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 112. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 113. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 114. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 115. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters  Many others Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 116. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters  Many others • Three broad sources for action method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 117. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters  Many others • Three broad sources for action method  Context objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 118. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters  Many others • Three broad sources for action method  Context objects  Method parameters Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 119. Action Method Input • Most methods need data to do work • Can come from a variety of sources  Environment  Operating system  Nature of user request  Direct parameters  Many others • Three broad sources for action method  Context objects  Method parameters  Model bindings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 120. Context Object Input Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 121. Context Object Input • Web requests come loaded with information Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 122. Context Object Input • Web requests come loaded with information  HTTP headers Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 123. Context Object Input • Web requests come loaded with information  HTTP headers  User information Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 124. Context Object Input • Web requests come loaded with information  HTTP headers  User information  Browser and capability information Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 125. Context Object Input • Web requests come loaded with information  HTTP headers  User information  Browser and capability information  User’s IP address Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 126. Context Object Input • Web requests come loaded with information  HTTP headers  User information  Browser and capability information  User’s IP address  Authentication information Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 127. Context Object Input • Web requests come loaded with information  HTTP headers  User information  Browser and capability information  User’s IP address  Authentication information • Information available through context objects Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 128. Parameter Input Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 129. Parameter Input • Specialized input customized for method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 130. Parameter Input • Specialized input customized for method • MVC takes care of populating values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 131. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 132. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 133. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form 2. RouteData.Values Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 134. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form 2. RouteData.Values 3. Request.QueryString Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 135. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form 2. RouteData.Values 3. Request.QueryString • Matches solely by name in order Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 136. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form 2. RouteData.Values 3. Request.QueryString • Matches solely by name in order  Once it finds a match it stops searching Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 137. Parameter Input • Specialized input customized for method • MVC takes care of populating values • Action invoker examines context objects for parameter values and uses model binder 1. Request.Form 2. RouteData.Values 3. Request.QueryString • Matches solely by name in order  Once it finds a match it stops searching  Have to coordinate names to avoid duplicate names Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 138. Model Bindings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 139. Model Bindings • Model encapsulates data and business rules Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 140. Model Bindings • Model encapsulates data and business rules  Use directly in controllers and views Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 141. Model Bindings • Model encapsulates data and business rules  Use directly in controllers and views  Built-in features to make easy Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 142. Model Bindings • Model encapsulates data and business rules  Use directly in controllers and views  Built-in features to make easy  Automatic data scaffolding Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 143. Controller Session State Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 144. Controller Session State • SessionState attribute Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 145. Controller Session State • SessionState attribute  Control how and whether controller uses session state Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 146. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 147. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available • SessionStateBehavior enumeration Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 148. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available • SessionStateBehavior enumeration  Default Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 149. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available • SessionStateBehavior enumeration  Default  Disabled Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 150. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available • SessionStateBehavior enumeration  Default  Disabled  ReadOnly Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 151. Controller Session State • SessionState attribute  Control how and whether controller uses session state  MVC uses session state by default, if available • SessionStateBehavior enumeration  Default  Disabled  ReadOnly  Required Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 152. Returning Action Results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 153. Returning Action Results • Action method follows a normal process Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 154. Returning Action Results • Action method follows a normal process  Receives request and data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 155. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 156. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 157. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 158. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses • Three broad types of results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 159. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses • Three broad types of results  HTML Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 160. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses • Three broad types of results  HTML  Redirect somewhere else Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 161. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses • Three broad types of results  HTML  Redirect somewhere else  Page data Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 162. Returning Action Results • Action method follows a normal process  Receives request and data  Process the request  Generates response • Many possible responses • Three broad types of results  HTML  Redirect somewhere else  Page data • All options based on ActionResult Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 163. Action Result Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 164. Action Result • ActionResult base class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 165. Action Result • ActionResult base class public abstract class ActionResult { public abstract void ExecuteResult(ControllerContext context); } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 166. Action Result • ActionResult base class public abstract class ActionResult { public abstract void ExecuteResult(ControllerContext context); } Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 167. Action Result • ActionResult base class public abstract class ActionResult { public abstract void ExecuteResult(ControllerContext context); } • ExecuteResult receives context information • Takes care of low-level work of generating a response Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 168. ActionResult Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 169. ActionResult Types Type Helper Method Description ContentResult Content() Raw text data EmptyResult -- Returns nothing FileResult File() Base class to send file HttpNotFoundResult HttpNotFound() Returns HTTP 404 HttpStatusCodeResult -- Returns any HTTP status HttpUnauthorizedResult -- Returns HTTP 401 JavaScriptResult JavaScript() Returns and executes script JsonResult Json() JavaScript Object Notation PartialViewResult PartialView() HTML snippet RedirectResult Redirect() Redirect to URL RedirectToRouteResult RedirectToRoute() Redirect to MVC route or action ViewResult RedirectToAction() View() Full HTML page Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 170. Passing Data to the View Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 171. Passing Data to the View • Use either ViewData or ViewBag Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 172. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 173. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 174. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 175. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary  But ViewData/ViewBag disappear after view rendered Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 176. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary  But ViewData/ViewBag disappear after view rendered  Session lasts for the user session Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 177. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary  But ViewData/ViewBag disappear after view rendered  Session lasts for the user session • ViewData is loosely typed Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 178. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary  But ViewData/ViewBag disappear after view rendered  Session lasts for the user session • ViewData is loosely typed • ViewBag is strongly typed Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 179. Passing Data to the View • Use either ViewData or ViewBag  Different faces of the same feature  A bit like ASP.NET Session object  Exposes ViewDataDictionary  But ViewData/ViewBag disappear after view rendered  Session lasts for the user session • ViewData is loosely typed • ViewBag is strongly typed  Uses dynamic language feature of C# and VB Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 180. ViewData and ViewBag Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 181. ViewData and ViewBag • Not limited to passing strings Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 182. ViewData and ViewBag • Not limited to passing strings • Keep in mind that they are same feature, but different Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 183. ViewData and ViewBag • Not limited to passing strings • Keep in mind that they are same feature, but different  Can mix and match in one action method/view Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 184. ViewData and ViewBag • Not limited to passing strings • Keep in mind that they are same feature, but different  Can mix and match in one action method/view  Get the same result either way Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 185. ViewData and ViewBag • Not limited to passing strings • Keep in mind that they are same feature, but different  Can mix and match in one action method/view  Get the same result either way  Generally should use ViewBag Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 186. ViewData and ViewBag • Not limited to passing strings • Keep in mind that they are same feature, but different  Can mix and match in one action method/view  Get the same result either way  Generally should use ViewBag • But in VB, using in controller requires setting Option Strict Off Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 187. Returning Text Data: ContentResult Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 188. Returning Text Data: ContentResult • HTML is dominant data format Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 189. Returning Text Data: ContentResult • HTML is dominant data format  But browsers can deal with variety of formats Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 190. Returning Text Data: ContentResult • HTML is dominant data format  But browsers can deal with variety of formats • Use a ContentResult for other formats Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 191. Returning Text Data: ContentResult • HTML is dominant data format  But browsers can deal with variety of formats • Use a ContentResult for other formats  Content helper method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 192. Returning Text Data: ContentResult • HTML is dominant data format  But browsers can deal with variety of formats • Use a ContentResult for other formats  Content helper method  Specify content as string Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 193. Returning Text Data: ContentResult • HTML is dominant data format  But browsers can deal with variety of formats • Use a ContentResult for other formats  Content helper method  Specify content as string  Optionally specify type, such as text/xml Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 194. Implicit Action Results Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 195. Implicit Action Results • Return text and don’t need to specify type Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 196. Implicit Action Results • Return text and don’t need to specify type • If type is not string, calls ToString method with InvariantCulture setting Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 197. Implicit Action Results • Return text and don’t need to specify type • If type is not string, calls ToString method with InvariantCulture setting  Wraps in ContentResult object Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 198. Missing Resource: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 199. Missing Resource: • Useful to indicate that requested resource is not available Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 200. Missing Resource: • Useful to indicate that requested resource is not available  User hacks a URL Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 201. Missing Resource: • Useful to indicate that requested resource is not available  User hacks a URL • Returns HTTP 404 status code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 202. Missing Resource: • Useful to indicate that requested resource is not available  User hacks a URL • Returns HTTP 404 status code  Can mask an exception that an attacker could otherwise use Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 203. Return any HTTP Status Code: Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 204. Return any HTTP Status Code: • More flexible than HttpNotFoundResult Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 205. Return any HTTP Status Code: • More flexible than HttpNotFoundResult • Can specify any HTTP status code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 206. Return any HTTP Status Code: • More flexible than HttpNotFoundResult • Can specify any HTTP status code  Optional description Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 207. Redirection Methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 208. Redirection Methods • Methods on the Controller class Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 209. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 210. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 211. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 212. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types  RedirectPermanent method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 213. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types  RedirectPermanent method  RedirectToRoutePermanent method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 214. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types  RedirectPermanent method  RedirectToRoutePermanent method  RedirectToActionPermanent method Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 215. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types  RedirectPermanent method  RedirectToRoutePermanent method  RedirectToActionPermanent method • Make easy to manage permanent redirections Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 216. Redirection Methods • Methods on the Controller class • Return instances of redirection action methods  Permanent property set to true • Types  RedirectPermanent method  RedirectToRoutePermanent method  RedirectToActionPermanent method • Make easy to manage permanent redirections  HTTP 301 status code Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 217. Learn More! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company
  • 218. Learn More! • This is an excerpt from a larger course. Visit www.learnnowonline.com for the full details! Learn More @ http://www.learnnowonline.com Copyright © by Application Developers Training Company

Notes de l'éditeur

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. DEMO: rest of section\n
  29. DEMO: rest of section\n
  30. DEMO: rest of section\n
  31. DEMO: rest of section\n
  32. DEMO: rest of section\n
  33. DEMO: rest of section\n
  34. DEMO: rest of section\n
  35. DEMO: rest of section\n
  36. DEMO: rest of section\n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. DEMO: rest of section\n
  79. DEMO: rest of section\n
  80. DEMO: rest of section\n
  81. DEMO: rest of section\n
  82. DEMO: rest of section\n
  83. DEMO: rest of section, Final Selection\n
  84. DEMO: rest of section, Final Selection\n
  85. DEMO: rest of section, Final Selection\n
  86. DEMO: rest of section, Final Selection\n
  87. DEMO: rest of section, Final Selection\n
  88. DEMO: rest of section, Final Selection\n
  89. DEMO: rest of section, Final Selection\n
  90. DEMO: rest of section, Final Selection\n
  91. DEMO: rest of section, Final Selection\n
  92. DEMO: rest of section, Final Selection\n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. DEMO: rest of section\n
  114. DEMO: rest of section\n
  115. DEMO: rest of section\n
  116. DEMO: rest of section\n
  117. DEMO: rest of section\n
  118. DEMO: rest of section\n
  119. DEMO: rest of section\n
  120. DEMO: rest of section\n
  121. DEMO: rest of section\n
  122. DEMO: rest of section\n
  123. DEMO: rest of section\n
  124. DEMO: rest of section\n
  125. DEMO: rest of section\n
  126. DEMO: rest of section\n
  127. DEMO: rest of section\n
  128. DEMO: rest of section\n
  129. DEMO: rest of section\n
  130. DEMO: rest of section\n
  131. DEMO: rest of section\n
  132. DEMO: rest of section\n
  133. DEMO: rest of section\n
  134. DEMO: rest of section\n
  135. DEMO: rest of section\n
  136. DEMO: rest of section\n
  137. DEMO: rest of section\n
  138. DEMO: rest of section\n
  139. DEMO: rest of section\n
  140. DEMO: rest of section\n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. DEMO: Render an HTML Page, Finding the View\n
  159. DEMO: most of rest of section\n
  160. DEMO: most of rest of section\n
  161. DEMO: most of rest of section\n
  162. DEMO: most of rest of section\n
  163. DEMO: most of rest of section\n
  164. DEMO: most of rest of section\n
  165. DEMO: most of rest of section\n
  166. DEMO: most of rest of section\n
  167. DEMO: most of rest of section\n
  168. \n
  169. \n
  170. \n
  171. \n
  172. \n
  173. \n
  174. DEMO: rest of section\n
  175. DEMO: rest of section\n
  176. DEMO: rest of section\n
  177. DEMO: rest of section\n
  178. DEMO: rest of section\n
  179. DEMO: rest of section\n
  180. DEMO: rest of section\n
  181. DEMO: rest of section\n
  182. DEMO: rest of section\n
  183. DEMO: rest of section\n
  184. DEMO: rest of section\n
  185. DEMO: rest of section\n
  186. DEMO: rest of section\n
  187. DEMO: rest of section\n
  188. DEMO: rest of section\n
  189. DEMO: rest of section\n
  190. \n
  191. \n
  192. \n
  193. \n
  194. \n
  195. \n
  196. \n
  197. \n
  198. \n
  199. DEMO: rest of section\n