FeaturesMvc enables a feature-based project structure for ASP.NET MVC. It currently consists of 2 projects.
FeaturesMvc enables views to be resolved from within a features folder.
As a picture says more than a thousand words, this is what your project structure could look like (left is the default structure, right is the feature-based structure):
In short, this structure keeps all files that encompass a feature, closer together. the default structure will quickly become a mess as a project grows. The features structure also works within
MVC Areas so you can group features together in an
FeaturesMvc packages are available at NuGet.
If you want the full package that resolves views from features folders including bundling support, install
FeaturesMvc.Bundling by running the following command in the Package Manager Console:
If you only want views to be resolved from features folders, install
FeaturesMvc by running the following command in the Package Manager Console:
To let ASP.NET MVC resolve views from within
~/Features/<FeatureName>/Views, you have to add Features support to the Razor ViewEngine.
FeaturesMvc includes an extension method to do just that. Execute the following code at application startup:
using XperiCode.FeaturesMvc; //... ViewEngines.Engines.AddFeatureSupportForRazorViewEngine();
Now you can add a Features folder to the root of your MVC Web Application, and start to add features. Note that the name of a feature folder should be the same name as the name of the feature controller.
Because the root folder of your views is now
/Features instead of
/Views, your views will not find
_ViewStart.cshtml anymore (if you are using it) and the
Web.config from the
/Views folder will not be used. Therefore you will need to copy over the
Web.config from the
/Views folder to the
That is all that is necessary to get the basic functionality working.
Web.config that is in the
/Features folder. By default, there is a
BlockViewHandler present that will prevent files from being downloaded from within the
/Views folder. As you copied over that
Web.config to the
/Features folder either.
So what we want to do, is only block views from being downloaded directly from the features folder, but allow any other files (like javscript and stylesheets). So change the handler from this:
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
<add name="BlockViewHandlerCS" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" /> <add name="BlockViewHandlerVB" path="*.vbhtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
Bundling and minification
Documentation is coming. In the meantime, check out the sample project on GitHub.