[RESOLVED]How to change views location for DisplayModeProvider

<div class="post-text" itemprop="text">

I develop massive web application with a lot of views. It is messy to keep desktop/mobile views in same folder. Is it possible to group mobile views (name.Mobile.cshtml) into explicit subfolder and say to DisplayModeProvider to find views there? For example:

Views/Home/Index.Mobile.cshtml

moves to

Views/Home/Mobile/Index.Mobile.cshtml

Views/People/List.Mobile.cshtml

moves to

Views/People/Mobile/List.Mobile.cshtml

</div>

You can use Areas (an ASP.NET MVC term, sometimes referred to as ‘Module’ in other MVC frameworks).

See here:

http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

In short, an Area will let you have controllers & views specific to the ‘Area’, like so:

Regular structure (default area):

/Models
/Controllers
/Views/[Controller]/[Action].cshtml
‘Admin’ area (for example):

/Areas/Admin/Models
/Areas/Admin/Controllers/
/Areas/Admin/Views/[Controller]/[Action].cshtml
As of routing, you’ll usually have to configure it manually by ‘registering’ areas in Global.asax

Thank you for your reply. I asked the same question on stackoverflow.com, then i found the solution and wrote message there. Here is the link:

http://stackoverflow.com/questions/26488321/asp-net-mvc-change-views-location-for-displaymodeprovider

Leave a Reply