How to redirect a pointer from another controller?

I was looking for an attempt to find a way to redirect to the Index view from another controller.

 public ActionResult Index() { ApplicationController viewModel = new ApplicationController(); return RedirectToAction("Index", viewModel); } 

Here is what I tried right now. Now the code that was provided to me has an ActionLink that links to the page, I also need Redirect .

 @Html.ActionLink("Bally Applications","../Application") 
+86
c # asp.net-mvc
Oct 25 '11 at 15:57
source share
5 answers

Use overloads that also accept the controller name ...

 return RedirectToAction("Index", "MyController"); 

and

 @Html.ActionLink("Link Name","Index", "MyController", null, null) 
+200
Oct 25 '11 at 15:59
source share

to try:

 public ActionResult Index() { return RedirectToAction("actionName"); // or return RedirectToAction("actionName", "controllerName"); // or return RedirectToAction("actionName", "controllerName", new {/* routeValues, for example: */ id = 5 }); } 

and in .cshtml :

 @Html.ActionLink("linkText","actionName") 

OR

 @Html.ActionLink("linkText","actionName","controllerName") 

OR

 @Html.ActionLink("linkText", "actionName", "controllerName", new { /* routeValues forexample: id = 6 or leave blank or use null */ }, new { /* htmlAttributes forexample: @class = "my-class" or leave blank or use null */ }) 

Notification using null in the final expression is not recommended, and it is better to use empty new {} instead of null

+19
Oct 25 '11 at 16:03
source share

You can use the following code:

 return RedirectToAction("Index", "Home"); 

See RedirectToAction

+10
Oct. 25 '11 at 15:59
source share

You can use the overload method RedirectToAction(string actionName, string controllerName);

Example:

 RedirectToAction(nameof(HomeController.Index), "Home"); 
+1
Jul 09 '17 at 18:20
source share

You can use local forwarding. The following codes jump to the HomeController index page:

 public class SharedController : Controller { // GET: /<controller>/ public IActionResult _Layout(string btnLogout) { if (btnLogout != null) { return LocalRedirect("~/Index"); } return View(); } } 
0
Dec 22 '15 at 5:18
source share



All Articles