Contents
Should each view have its own controller?
Absolutely not. Design your application in a logical and consistent way. A controller usually handles many actions and returns many different views. You could consider having a FAQController to render all the views, for both user and admin.
Can a controller have two views?
Yes You can use multiple View in one Controller.
What is a controller folder?
The Controllers folder contains class files for the controllers. A Controller handles users’ request and returns a response. MVC requires the name of all controller files to end with “Controller”. You will learn about the controller in the next section.
How model view and controller interact with each other?
The controller is only for interacting with the user. Typically the view fetches the necessary information from the model. When using passive views, objects (from the model) are passed from the controller. Important is that the view only reads from the model and never writes/updates it.
What is meant by model view controller?
Model–view–controller (usually known as MVC) is a software design pattern commonly used for developing user interfaces that divide the related program logic into three interconnected elements.
Why are my controllers in a different folder?
Remember it’s the Microsoft recommended way to keep the controllers and views in different folder, so many would follow recommended structure, One reason could be controllers always does not have one to one relationship with views, especially the partial views can be shared among controllers.
Why are views and controllers in separate directories?
Also if it’s generic enough I can probably use that module in other sites just by changing the configuration or package it as a library and publish it as OSS. One reason to keep views and controllers in separate directories is when you have front end and back end developers working on a project.
What happens if you throw all the views in one folder?
By throwing all the views in one folder and all the controllers in another folder you are creating two packages with very very tight coupling. This goes against the principle of having weak inter package dependencies.
The shared directory is there specifically to share Views across multiple controllers. Just add your View to the Shared subdirectory and you’re good to go. If you do return View(“~/Views/Wherever/SomeDir/MyView.aspx”)You can return any View you’d like. Share Improve this answer Follow edited Sep 21 ’15 at 19:50