Controller search structure mvc 5

Asked

Viewed 142 times

1

I have a normal application in mvc 5 and would like to change the basic folder convention for controllers/views.

For example:

  • /Controllers/Admin/Controller1.Cs
  • /Controllers/Admin/Controller2.Cs

and when I create views, I follow the existing convention:

  • /Views/Controller1/Index.cshtml
  • /Views/Controller2/Index.cshtml

The problem is this: no action, when I use the option "Go To View" it correctly finds the view, but winter doesn’t work. In the view, when I use the option "Go To Controller" get the message "Unable to find a matching controller".

I can’t consider the use of areas because the next version of the mvc will come without it.

Is there any solution to this?

1 answer

0


Not.

Visual Studio supposes all its Controllers are in the default project structure, that is, just below the directory Controllers.

There is no way to change this behavior, because Views do not refer directly to Controllers. What Visual Studio does is examine the directory in which these Views are and deduce which the Controller theirs.

Note that using the shortcut in ~/Views/Shared/Layout.cshtml, you will have the same message. And this is correct, because Layout files do not belong to Controller some.

  • It’s a shame... I thought there was some way to simulate this mechanism as it occurs using the areas mechanism at least. Know if it is possible?

  • I did some research before answering and found nothing, unfortunately.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.