Kelly Cline
Kelly Cline

Reputation: 2246

In ASP.NET MVC 4, where is the connection between controller and view stored?

New to ASP.NET MVC, I understand that, if I right-click in an action within my controller, the context menu gives me Add View, and Go To View. Where does the app store that connection? I have searched all the files in the app for the name of one of my views (cshtml files), and haven't seen anywhere that a particular one is connected to any particular controller, let alone controller method.

I know this is a newbie question, but I have searched around for an answer and haven't come up with one.

Upvotes: 3

Views: 2847

Answers (1)

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

The answer is that it doesn't store this 'connection'. MVC uses a concept known as "Convention over Configuration". This means that MVC "infers" various things based on conventions. In this case, the convention is that the view is automatically found if it's in a folder in the Views Directory with the same name as the controller, and the same name as the method.

You can override this, by passing a view name in the View() call, but otherwise it just figures it out at runtime.

The IDE also uses this convention, and it has parsed your code file and knows to "Go to" the file specified by convention.

Upvotes: 5

Related Questions