How do I access a view from a different controller?
Loading
How do I access a view from a different controller?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Deepak TewatiaRank #142 · 16K reputationPosted Jan 26, 2023, 9:28 AM EST
Hi Wasim,
We have two methods to access a view from different controller in MVC:
Method-1
using the "RedirectToAction" method is as follows:
return RedirectToAction("ActionName", "ControllerName");Method-2
using "View" method of the controller:
return View("ViewName", "ControllerName");Sachin SinghRank #66 · 26.2K reputationPosted Jan 26, 2023, 10:02 AM EST
Or you can also give the full path of the view
return View("~/Views/About/about.cshtml")Anupam MaitiRank #295 · 8.5K reputationPosted Jan 27, 2023, 1:04 PM EST
You can access a view from a different controller by using the "RedirectToAction" method as like below
return RedirectToAction("Index", "Home");
You can also use the "View" method to access a view from a different controller.
return View("Index","Home");
Uday DodiyaRank #239 · 10.3K reputationPosted Jan 28, 2023, 4:07 AM EST
In ASP.NET MVC, you can access a view from a different controller by using the
RedirectToActionmethod. TheRedirectToActionmethod takes two parameters: the name of the action and the name of the controller.For example, if you want to redirect to the
Indexaction of theHomecontroller from theAccountcontroller, you can use the following code:return RedirectToAction("Index", "Home");Alternatively, you can use the
Viewmethod to render a specific view from a different controller. TheViewmethod takes one parameter, the name of the view.For example, if you want to render the
Indexview of theHomecontroller from theAccountcontroller, you can use the following code:return View("~/Views/Home/Index.cshtml");Note that the
Viewmethod is used to return the view from the current action, theRedirectToActionmethod is used to redirect to a different action.Vishal JoshiRank #377 · 6.7K reputationPosted Jan 27, 2023, 5:17 AM EST
Hello,
Thanks
Amit MohantyRank #112 · 20K reputationPosted Jan 27, 2023, 6:42 AM EST
You can access a view from a different controller using the RedirectToAction method.
return RedirectToAction("Index", "YourController");The RedirectToAction method will cause a new HTTP request to be made to the server, which will result in a new instance of the controller being created. If you want to pass data to the new controller without causing a new request, you can use the RedirectToRoute method instead.
You can also use View() method to return a view from a different controller by specifying the full name of the view including the controller name.
return View("~/Views/YourController/Index.cshtml");