0

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

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

you are absolutely right.. I am working with "Razor View Empty" at the moment.. gosh I should have tested the other option to realise that. Sorry. But the behavior is still weird somehow isn't it? I mean if you click on the controller's action menu, although you ask for an empty view, you still want that view to be included that controller's view folder.. Thank you Zhi Lv - MSTF
0

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

1 Comment

:-D no, the image was to show that the view is actually created, but the automatic folder creation, naming with created view in this folder is not working.. I know how to create a view :-) thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.