Francois
Francois

Reputation: 159

Asp.net Core web application (MVC) Adding a view from controller's action menu not working properly

I just created a brand new Asp.net Core Web Application (MVC) to reproduce a problem I have with another project.

When I try adding a view from the controller's action menu (right click > add a view) it creates a view within the Controller's folder instead of creating a new subfolder in the Views folder, naming it and placing the created view inside it.

My dotnet version is 3.1.401 and I am on Microsoft Visual Studio Community 2019 Version 16.7.2.

See underneath, the "index.cshtml" placed within the Controller folder. I am expecting a "Test" subfolder created in the Views folder and that "index.cshtml" view placed in it.

-- update :

The image underneath is to show where the view created from the controller's action menu (right click > add a view) ends up... Another precision, after I have created the folder manually and placed one view into it, any further views created with (right click > add a view) end up in the right folder automatically.

enter image description here

Upvotes: 0

Views: 1056

Answers (2)

Zhi Lv
Zhi Lv

Reputation: 21636

When you click the "Add View..." option to add view, perhaps you are select the "Razor View - Empty" template, screenshot as below:

enter image description here

After clicking the Add button, it will add a View page in the Controller folder.

To add a new view page in the subfolder under the Views folder, you could select the second item ("Razor View"):

enter image description here

Then, enter the view name and select model template:

enter image description here

After clicking the Add button, the view will add in the Views folder:

enter image description here

Upvotes: 1

shrzd
shrzd

Reputation: 104

You are doing it in wrong way. In order to create a view for the specific Controller action you should go to you controller, put cursor in the name of desired action and click right button of a mouse. Then you will have an option to create a View for this action by clicking to Add View.

Look image below: enter image description here

Upvotes: 0

Related Questions