What code does Visual Studio add (and where is it put?) when you right-click the controller method to link to the view?
How can one do this (link the controller & view) without Visual Studio?
MVC by default will find a View that matches the name of the Controller Action itself (it actually searches both the Views and Shared folders to find a cooresponding View that matches). Additionally, Index is always the "default" Controller Action (and View).
It is all by convention. You place your views in the Views/ControllerName folder for every controller and that's the default location for framework to look for. But it is not a must in any way.
When in your controller you write
return View();
Framework assumes you want the view with the same name as action name and looks for it in Views/Controller/ folder. Then Views/Shared.
But in your actions you can write
return View("ViewName");
Framework will look for a View named "ViewName" then in same folders.
So default name for a view would be the name of action being executed. And that's a convention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With