Have you ever tried to create scaffolding around a building?
Or better yet, how about putting some scaffolding up around a hungry Amoeba?
This code is a
link to a closed solution on codeplex so you don't have to use Areas. But the scaffolding is broken and needs to be fixed. First off I wanted to create a directory "inside" the controller, view, model that represents the
namespace. In Sql they have this thing called a schema, and in c# code they have namespaces. And on the file system they have directories. Unfortunately when using the entity framework there is no way to push these out into their own directory
within the models, views, and controllers directories. But I think that it would be nice. In this solution I've only created a single directory: Department. In the link I think I switch to just dept, so you won't be able to get them both working together
unless you decide on Department or Dept for short.
So first off let me vent my frustration about not being able to change how and where and even why the MVC 4.5 framework defaults adding new controllers and views and even models right off the bat. Why make it so strict? What happened to separation of concerns?
Who is really implementing my code? Why can't I add a directory in the controller, view, or model if I want to and just tweak the implementation. I don't get it, luckily there is something called a routing engine and you create your own implementation that
ignores the standard model which is vexing, limiting, and irritating to someone who wants to make it behave a certain way.
So here is what I tried to do to get around it.... the
code in the link above I placed in the app_start directory and in the routing file I added a link of code like so:
routes.MapRoute(
name: "Department",
url: "Department/{controller}/{action}/{id}",
defaults: new { controller = "DepartmentHome", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MBNMVC.Controllers.Department" }
);
routes.MapRoute(
name: "DepartmentHome",
url: "Department/{controller}/{action}/{id}",
defaults: new { controller = "DepartmentHome", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MBNMVC.Controllers.Department" }
);
routes.MapRoute(
name: "DepartmentAccount",
url: "Department/{controller}/{action}/{id}",
defaults: new { controller = "DepartmentAccount", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "MBNMVC.Controllers.Department" }
);
);
The only problem with this is that the scaffolding powershell is all messed up. Luckily there is something called custom scaffolding which
is on
channel 9. The only other thing I want is have just one mvc directory which contains the controller,view,and model.
Anyway the moral of the story is if you want to deviate from the standard it is possible but not recommended.