In this article we will see how to use a redirect result in a controller in MVC.
IntroductionIn this article we will see how to use a redirect result in a controller in MVC.Step 1Create a MVC project from the "Empty" template.Right-click on "Controllers" and select "Add" >> "Controller...".Step 2Select "MVC 5 Controller - Empty" to add an empty controller.Click on the "Add" button.Step 3Name the controller as in the following:And it will add an action result method in the controller.Step 4Now we need to create a view.Right-click on "Index" and select "Add View...".Step 5Name the view and select "Empty (without model)" as the template.Click on the "Add" button.Step 6Redirect creates a redirect result object that redirects to the specific URL and redirect permanent returns an instance of a redirect result class with the permanent property set to true.Step 7Now we need to create a view.Right-click on "redirect" and select "Add View...".Step 8Name the view and select "Empty (without model)" as the template.Click on the "Add" button.Step 9Add a title to the about us page.Step 10Add two links, one is for the redirect and another is for a redirectpermanent as follows:Step 11Run the project and click on "About Us Redirect".In the redirect case the about us page is rendered with http status code 302. You can find this using Firebug.Step 12Now click on "About Us Redirect Permanent".In the redirect permanent case, the about us page is rendered with HTTP Status Code 30. << Day 9 >> Day 11
Hands on ASP.NET GridView