Reputation: 15069
I am new to ASP.Net programming. I have created an empty MVC controller called TestController, and as I follow the tutorial it says right click on the Index method of the Controller , then click Add View.
The View is successfully created and with I open the page
http://localhost:9993/Test
It successfully opens the relevant view file (Views->Test->Index.cshtml)
My question is where exactly in the code is the mapping defined that relates a View to a Controller ? Because when I open the controller, it has no information about which View file it relates to and Vice versa
Upvotes: 1
Views: 2180
Reputation: 2524
By default ASP.NET MVC searches appropriate views in {controller} subfolder of Views folder, where {controller} is a name of ASP.NET MVC Controller class without word "Controller", and in Views/Shared folder.
Upvotes: 0
Reputation: 4381
In RouteConfig.cs
(App_Start
folder), your routes are defined. You can add or customize them there, in order to get to the right action in the right controller.
About views, it works by convention : if a controller is named TestController
, and the action is named Index
, it will search for an Index.cshtml
view in a Views\Test
folder (or Views\Shared
if you wish to reuse a view across multiple controllers)
Upvotes: 3