Asp.Net MVC Exploring Controllers in depth Part 4. Best Dot Net Training

 Asp.Net MVC Exploring Controllers in-depth Part 4. Best Dot Net Training

MVC – Action Filters

Action filters will apply pre or post Processing logic to a controller action and its result. Action filters are the component we want to use to apply cross-cutting logic to our application i.e. the logic that we must execute across multiple controller actions but we do not want to duplicate the logic inside of the individual controller.

Name Description
OutputCache Cache the output of an Action method.
Authorize Restrict an action or controller to authorize user or role.
ValidateInput Turn on/off the request validation.
ValidateAntiForgeryToken Helps prevent cross site request forgeries.
HandleError Can specify a view to render in the event of an unhandled exception.

                OutputCache: tells the runtime that it allows to cache the final output of the action and use the cached result to serve the future request.

[OutputCache(Duration=10, VaryByParam=”t1″)]

               Authorize: Authorize attribute to allow us to ensure that the user is login before action/controller allow to process the request. Continue reading “Asp.Net MVC Exploring Controllers in depth Part 4. Best Dot Net Training”

Please follow and like us:
0

Asp.Net MVC Exploring Controllers in-depth Part 3

Asp.Net MVC Exploring Controllers in-depth Part 3 Action Selectors

When the MVC Framework is selecting one of the controller public methods to invoke as an action, it will use any

action selector attribute that might be present to define the correct action to invoke.

  1. ActionName
  2. AcceptVerbs
    • HttpPost
    • HttpGet

ActionName: When we apply this to a controller action it will specify the action name for that method.

For the Index method, we have bellow we no longer reach this method as action name “Index”. We have to reach this method as “Start”. (http://localhost:123/Home/Start) Continue reading “Asp.Net MVC Exploring Controllers in-depth Part 3”

Please follow and like us:
0

Asp.Net MVC Exploring Controllers in depth Part 2.Best Dot Net Courses

Asp.Net MVC Exploring Controllers in-depth Part 2.Best Dot Net Courses

 

Learn MVC to build web apps using the Model View Controller pattern. ASP.NET MVC 5 provides this functionality to the ASP.NET framework as an alternative to the Web Forms pattern

Passing data from Controller to View

ViewBag vs. ViewData vs. TempData

All three are properties

    • ViewData is a dictionary object that you put data into, which then becomes available to the ViewData is a derivative of the ViewDataDictionary class, so you can access by the familiar “key/value” syntax.
    • ViewBag object is a wrapper around the ViewData object that allows you to create dynamic properties for the ViewBag.
    • Both the ViewData and ViewBag objects are great for accessing extra data (i.e., outside the data model), between the controller
    • Asp.Net MVC Exploring Controllers in-depth Part 2.Best Dot Net Courses

Continue reading “Asp.Net MVC Exploring Controllers in depth Part 2.Best Dot Net Courses”

Please follow and like us:
0

Asp.Net Mvc Controllers Overview

Controller Overview

The ASP.NET MVC framework maps URLs to classes that are referred to as controllers.

Controllers

  • Process incoming requests
  • Handle user input and interactions and
  • Execute appropriate application

The Controller class inherits from ControllerBase and is the default implementation of a controller. The Controller class is responsible for the following processing stages:

  1. Locating the appropriate action method to call and validate that it can be
  2. Getting the values to be used as the action method’s
  3. Handling all errors that might occur during the execution of the action
  4. Providing the View for rendering ASP.NET pages to

Continue reading “Asp.Net Mvc Controllers Overview”

Please follow and like us:
0