سؤال

Im currently implementing MVC into a fairly large project and want to sort views into categories. MVC dont seem to understand this and Im having problems finding a clean solution. Basically I was hoping to solve this with routes, but it isnt working.

My folder structure in the project is like this:

- Controller
  - SLResources
    - FAQController.cs

...

- View
  - SLResources
    - FAQ
      - (cshtml files in here)

Ive also tried adding a - FAQ folder after - SLResources in the controller folder structure.

Ive then made the following routing, with no luck:

RouteTable.Routes.MapRoute(
   name: "FAQ",
   url: "SLResources/FAQ/{action}/{id}",
   defaults: new { controller = "FAQ", action = "Index", id = UrlParameter.Optional }
);

basically I would like to reach the FAQ by using this url: http://www.xxxxxxxx.com/SLResources/FAQ/

Is the only solutions to either create a dummy class that redirects to the proper views, or a custom ViewEngine?

Any tips?

هل كانت مفيدة؟

المحلول

If your goal is to have the url with SLResources/FAQ, then you don't need to create a separate folder in the Views.

Your route already does that for you. Leave your route as is, and put your cshtml files in the 'Views>FAQ' folder and it will work.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top