Last post Apr 11, 2019 01:48 AM by Nan Yu
Apr 09, 2019 01:42 PM|stevehav|LINK
I'm developing an application that's becoming sizable, in terms of number of views that a given user might interact with.
I started with a handful of controllers, one controller for each major area of functionality for the application (think one for users, called /Users, and one for administrators, called /Admin). Each of these has now grown to where it starts to feel unwieldy
-- the /Users controller has about 50 actions now.
Is there a way to build sub-controllers, so that the routes look nice, like /Users/Settings, so that I can still group related actions into controllers but split them up into logical subgroups?
Ideally, I think, the directory structure and routes would reflect something like:
/Controllers/Users.cs, /Controllers/Users/UserSettings.cs, /Views/Users/Index.cshtml, /Views/Users/Settings/Index.cshtml, and so on.
My other thought was to split them up (UsersController.cs, UsersSettingsController.cs, etc) and then manually specify routes to methods to maintain a nice, logical grouping of routes, but that seems clumsy and easily broken.
Apr 09, 2019 01:51 PM|bruce (sqlwork.com)|LINK
see MVC areas for breaking the project into a user area and an admin area.
Apr 09, 2019 03:20 PM|stevehav|LINK
Thanks, that looks like it's exactly what I was hoping for!
Now, I'm running into another problem.
I've moved some code into an area, but for some reason, when I POST data to an action, it's always coming in empty.
The POST action looks like this:
public IActionResult SettingsPost(GeneralSettingsViewModel vm)
But no matter what, the "vm" object always comes in with all values null.
When this wasn't in an area, but just in the original controller, it worked fine.
Is there something else I'd need to do to get POST methods to work inside areas?
Apr 11, 2019 01:48 AM|Nan Yu|LINK
Hi stevehav ,
You may provide the codes about posting data , via ajax or form post ?