MVC 2.0 areas and routinghttp://forums.asp.net/t/1558530.aspx/1?MVC+2+0+areas+and+routingTue, 18 May 2010 02:20:27 -040015585303840434http://forums.asp.net/p/1558530/3840434.aspx/1?MVC+2+0+areas+and+routingMVC 2.0 areas and routing <p>Amigos,</p> <p>I'm attempting to create an area within my application called 'Admin'. Within this area I have the subfolders 'Blog', 'Dashboard', 'Newsletters'. 'Blog' will have its own subfolders 'Posts', 'Tags' and 'Comments'. I've created an AreaRegistration class for the area 'Admin':</p> <p></p> <pre class="prettyprint">using System.Web.Mvc; namespace FirstSolution.Web.Controllers.Admin { public class AdminAreaRegistration : AreaRegistration { public override string AreaName { get { return &quot;Admin&quot;; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( &quot;Admin_default&quot;, &quot;Admin/{controller}/{action}/{id}&quot;, new { action = &quot;Index&quot;, id = &quot;&quot; }, new string[] { &quot;FirstSolution.Web.Controllers.Admin&quot; } ); } } }</pre> <p>I'm successfully able to link to 'Admin''s subfolders using Html.ActionLink("Admin/Dashboard", "Index", "Dashboard", new { area = "Admin" }, null). But I'm having difficulty linking to 'Admin/Blog/Posts'. I attempted to define a new area for 'Admin/Blog':</p><p><br></p><pre class="prettyprint">using System.Web.Mvc; namespace FirstSolution.Web.Controllers.Admin.Blog { public class BlogAreaRegistration : AreaRegistration { public override string AreaName { get { return "Admin/Blog"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_Blog_default", "Admin/Blog/{controller}/{action}/{id}", new { action = "Index", id = "" }, new string[] { "FirstSolution.Web.Controllers.Admin.Blog" } ); } } }</pre> <p>But I can't link to 'Admin/Blog' subfolders. For example when attempting to link to 'Admin/Blog/Posts' via Html.ActionLink(&quot;Admin/Blog/Posts&quot;, &quot;Index&quot;, &quot;Posts&quot;, new { area = &quot;Admin/Blog&quot; }, null) I receive a &quot;resource can not be found&quot; error. I'm assuming the method I'm mapping these subfolders is incorrect. Any assistance is appreciated. Also note, that I'm using Sharp Architecture framework 1.5.2 too.</p> 2010-05-15T18:26:15-04:003840595http://forums.asp.net/p/1558530/3840595.aspx/1?Re+MVC+2+0+areas+and+routingRe: MVC 2.0 areas and routing <p>Any chance you could post up the file hierarchy for your solution (relevant to the admin area)?</p> <p><br> </p> 2010-05-15T21:43:57-04:003840612http://forums.asp.net/p/1558530/3840612.aspx/1?Re+MVC+2+0+areas+and+routingRe: MVC 2.0 areas and routing <p><img src="file:///C:/Users/Tyler/AppData/Local/Temp/moz-screenshot.png"></p> <p>Hey Nick. Thanks for the reply! Below is the file hierarchy. Let me know if you need any more information.</p> <p><br> </p> <p>Admin</p> <p>Admin/Blog</p> <p>Admin/Blog/Posts</p> <p>Admin/Blog/Posts/Index.aspx<br> </p> <p>Admin/Dashboard</p> <p>Admin/Dashboard/Index.aspx<br> </p> <p>Admin/Newsletters</p> <p>Admin/Newsletters/Index.aspx<br> </p> <p>Admin/Shared</p> <p><br> </p> <p>After reading a little more on areas and routing it seems like defining a Blog area underneath Admin is unnecessary. I think I may need to add a new map route to the Admin area. Something similiar to:</p> <p><pre class="prettyprint">context.MapRoute( null, &quot;Admin/Blog/{controller}/{action}/{id}&quot;, new { action = &quot;Index&quot;, id = &quot;&quot; }, new string[] { &quot;FirstSolution.Web.Controllers.Admin.Blog&quot; } );</pre><br> But I have been unsuccessful in creating the proper route.<br> </p> 2010-05-15T22:02:47-04:003840953http://forums.asp.net/p/1558530/3840953.aspx/1?Re+MVC+2+0+areas+and+routingRe: MVC 2.0 areas and routing <p>you are thinking in a&nbsp;wrong diection. First of all,&nbsp;In routing there is&nbsp;no one to one relationship between folder name and route.</p> <p>I will suggest you to read the core routing to understand what is behind the scene.</p> <p>I will recommend the Routing chapter&nbsp;&nbsp;of following books,</p> <p>Professional ASP.NET MVC(Rob Conery,...), Pro ASP.NET MVC(Steve Sanderson), Programming Microsoft ASP.NET MVC&nbsp;(Dino Espatio)</p> 2010-05-16T02:47:32-04:003844406http://forums.asp.net/p/1558530/3844406.aspx/1?Re+MVC+2+0+areas+and+routingRe: MVC 2.0 areas and routing <p>Thank you for the recommendations. </p> <p>I was able to resolve my issue. I removed the &quot;Blog&quot; area and created a custom route within the &quot;Admin&quot; area to manage the 'Blog'.<br> </p> 2010-05-18T02:20:27-04:00