Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC Areas Routing - Controller Folder with Folder
    primarykey
    data
    text
    <p>Currently I have a folder structure like this:</p> <pre><code>Area (folder) - Toolkit (folder) - Controllers (folder) - AdminController.cs - Views (folder) - Admin (folder) - Privledges (folder) - Create.cshtml - Edit.cshtml - Delete.cshtml </code></pre> <p>Which translates to</p> <pre><code>/Toolkit/{controller}/{action}/{tool}/{id} </code></pre> <p><strong>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?</strong></p> <p>The implementation of what I am talking about:</p> <pre><code> 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); } </code></pre> <p>When I write a View, I have to make sure the Path name is used for the folder</p> <pre><code>@Html.ActionLink("Edit", "./Toolkit/Admin/Priveleges/Edit", "Admin", new { id = item.id }) </code></pre> <p>This seems to be a poor practice, because if the folder structure changes at all it will require a lot of maintenance. </p> <p>However, if I have to break out the actions into controllers there would be many of them (almost 20 with more added over time). </p> <p><strong>If what I am doing is a bad practice, what would be the best way to serve a route that looks like this?</strong></p> <pre><code>/Toolkit/Admin/Privileges/Edit/1 </code></pre> <p>I want to <strong>avoid</strong> doing the following:</p> <pre><code>/Toolkit/Admin/CreatePrivileges/1 /Toolkit/Admin/EditPrivileges/1 /Toolkit/Admin/DeletePrivileges/1 </code></pre> <p><em>Please let me know if I'm not making any sense, because I am having a hard time putting this question into words.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload