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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Uday DodiyaPosted Jan 28, 2023, 9:07 AM
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: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:Note that the
Viewmethod is used to return the view from the current action, theRedirectToActionmethod is used to redirect to a different action.Anupam MaitiPosted Jan 27, 2023, 6:04 PM
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");
Amit MohantyPosted Jan 27, 2023, 11:42 AM
You can access a view from a different controller using the RedirectToAction method.
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.
Vishal JoshiPosted Jan 27, 2023, 10:17 AM
Hello,
Thanks
Sachin SinghPosted Jan 26, 2023, 3:02 PM
Or you can also give the full path of the view
Deepak TewatiaPosted Jan 26, 2023, 2:28 PM
Hi Wasim,
We have two methods to access a view from different controller in MVC:
Method-1
using the "RedirectToAction" method is as follows:
Method-2
using "View" method of the controller: