1

I am trying to figure out how to use MVC for a new project. The project will have the following architecture:

enter image description here

Multiple projects will be possible to create.

The database is shared meaning that there are tables: Projects, Classes, Students, Assignments.

The only thing that bothers me is the routing. With MVC you are supposed to use the pattern Controller/Action/Parameter but in this case it is not possible. The routing pattern that I want to use is something like Project/ProjectId/Controller/Parameter/Action (project/1/class/1/edit).

I read about areas but this won't give me the extra layer that I want. It will just add something like the following(project/class/1/edit).

So how do you put together such things with MVC? Do I need to manually write every url pattern using the Route attribute?

I tried that also but I found myself repeating the pattern

Route("/project/{projectId}/morestuffhere")

which makes me think that I am doing this the wrong way.

YoloQ
  • 45
  • 5
  • 1
    What is stopping you from creating a route like `Project/{projectid}/{controller}/{id}/{action}` – Nkosi Jan 01 '18 at 11:12
  • [This](https://gist.github.com/AlexZeitler/2024730) might be of help. – Yurii Jan 01 '18 at 11:13
  • Possible duplicate of [Multiple levels in MVC custom routing](https://stackoverflow.com/questions/31934144/multiple-levels-in-mvc-custom-routing) – NightOwl888 Jan 01 '18 at 11:18
  • So you basically write your controllers and then you just go and map those to something else. – YoloQ Jan 01 '18 at 11:50
  • @Yuriy With that I will need to include the projectId in every action. – YoloQ Jan 01 '18 at 13:02
  • @YoloQ: You might want to think about project as a context the app is running in for an user. So, generally speaking you want to let user select/change a project(from list, drop-down, etc.) and work inside this context/project. You can do that by setting project id for current user/session somewhere(cookie, session, database). Then you will be able to use the default route(/class/edit/1, /student/3, etc). – dropoutcoder Jan 01 '18 at 13:32

0 Answers0