This blog explains the different methods that could be used for page redirection.
Method 1:
Using ActionLink. By using the Html.ActionLink, can specify the link name, the action name to be called and the controller name where the action is defined. Also can specify any arugements/parameters if exist. Thus, here on clicking the link - the controller will be moved to the action method which is defined and its respective return view() will be returned.
Method 2:
By using return View(). Any action method should return a View. Thus, for page navigation one can use this method by specifying the View name and the parameters if any. But, the control will not be moved to the navigated get Mehtod. All the required initial values has to be again defined in the existing action method, this makes the view to be reurned from the existing action method.
The main drawback of this method is - code duplication.
Method 3:
By using RedirectToAction(). Control can be passed from one Action method to another Action method using RedirectToAction(). So, in the current Action method - when we want to navigate to another page we give return RedirectToAction("action name"). Thus, this would call up the action method specified and its respective return View() is been rendered. Using this method one can pass the action name, controller name and the parameters if any.
Advantage: Avoid code duplication
example :
return RedirectToAction("DestinationPage", new { page = 1 });
where page is the parameter name.
In all the three methods the parameter name to be specified are case sensitive.
No comments:
Post a Comment