Reputation: 5027
I have a huge MVC application but unfortunately MVC Areas were not used in initial development. The application is becoming so modular that we feel there is a good case to be made for using Areas. How easy or hard is to move the entire code to "Areas" structure .. Are there any big challenges / code re-work etc kind of things that I have to be aware of ? Can I just create new Areas and move controllers views models into appropriate buckets ... And it works fine ? Am I over simplifying things? If anyone has taken this route before, would appreciate feedback, comments..
Upvotes: 4
Views: 200
Reputation: 82267
The application will work just fine with areas. It will make it easier to maintain, and to view logically because of the separation. However, you are going to encounter a few dilemmas.
Namespaces
The first will more than likely be namespaces. As you separate out connected logic or models with dependencies, their namespace references may need to change if dependent classes are placed in areas. Luckily, Visual Studio can handle these with the simple "Resolve" functionality. The compiler should throw up if you try to compile and show you all the places where there is an issue. It can be hard to foresee where all these occurrences will be. However, there will more than likely not be many using directives that are required because most of what is used by many different controllers should be in one place.
Routing
Just about every action link you use is going to have to change if you are going to use areas. You will be forced to change them to represent the new areas.
No area (in the base):
@Html.ActionLink("Label For Link", "ActionName", "ControllerName", new { area = "" }, null)
Specific area:
@Html.ActionLink("Label For Link", "ActionName", "ControllerName", new { area = "SpecificAreaName" }, null)
You may also need to change any return RedirectToAction
code you have.
Base area:
return RedirectToAction("ActionName", "ControllerName");
Specific Area:
return RedirectToAction("ActionName", "ControllerName", new { Area = "SpecificAreaName" });
Other than this, you should be good.
Upvotes: 6