Currently I have a folder structure like this:
Area (folder)
- Toolkit (folder)
- Controllers (folder)
- AdminController.cs
- Views (folder)
- Admin (folder)
- Privledges (folder)
- Create.cshtml
- Edit.cshtml
- Delete.cshtml
Which translates to
/Toolkit/{controller}/{action}/{tool}/{id}
Is it a bad practice to set up the action to behave a like a controller that serves up a view based on the string {tool} parameter and parameter {id} passed to the action?
The implementation of what I am talking about:
private const string FOLDER_PRIVILEGES = "./Privileges/";
public ActionResult Privileges(string tool, string id = "")
{
dynamic viewModel = null;
ToolViews view; // enum for the views
// Parse the tool name to get the enum representation of the view requested
bool isParsed = Enum.TryParse(tool, out view);
if (!isParsed)
{
return HttpNotFound();
}
switch (view)
{
case ToolViews.Index:
viewModel = GetIndexViewModel(); // call a function that gets the VM
break;
case ToolViews.Edit:
viewModel = GetEditViewModelById(int.Parse(id)); // sloppy parse
break;
default:
viewModel = GetIndexViewModel();
break;
}
// The folder path is needed to reach the correct view, is this bad?
// Should I just create a more specific controller even though it would
// require making about 15-20 controllers?
return View(FOLDER_PRIVILEGES + tool, viewModel);
}
When I write a View, I have to make sure the Path name is used for the folder
@Html.ActionLink("Edit", "./Toolkit/Admin/Priveleges/Edit", "Admin", new { id = item.id })
This seems to be a poor practice, because if the folder structure changes at all it will require a lot of maintenance.
However, if I have to break out the actions into controllers there would be many of them (almost 20 with more added over time).
If what I am doing is a bad practice, what would be the best way to serve a route that looks like this?
/Toolkit/Admin/Privileges/Edit/1
I want to avoid doing the following:
/Toolkit/Admin/CreatePrivileges/1
/Toolkit/Admin/EditPrivileges/1
/Toolkit/Admin/DeletePrivileges/1
Please let me know if I'm not making any sense, because I am having a hard time putting this question into words.