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':
using System.Web.Mvc;
namespace FirstSolution.Web.Controllers.Admin
{
public class AdminAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Admin";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = "" },
new string[] { "FirstSolution.Web.Controllers.Admin" }
);
}
}
}
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':
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" }
);
}
}
}
But I can't link to 'Admin/Blog' subfolders. For example when attempting to link to 'Admin/Blog/Posts' via Html.ActionLink("Admin/Blog/Posts", "Index", "Posts", new { area = "Admin/Blog" }, null) I receive a "resource can not be found" 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.
Hey Nick. Thanks for the reply! Below is the file hierarchy. Let me know if you need any more information.
Admin
Admin/Blog
Admin/Blog/Posts
Admin/Blog/Posts/Index.aspx
Admin/Dashboard
Admin/Dashboard/Index.aspx
Admin/Newsletters
Admin/Newsletters/Index.aspx
Admin/Shared
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:
context.MapRoute(
null,
"Admin/Blog/{controller}/{action}/{id}",
new { action = "Index", id = "" },
new string[] { "FirstSolution.Web.Controllers.Admin.Blog" }
);
But I have been unsuccessful in creating the proper route.
you are thinking in a wrong diection. First of all, In routing there is no one to one relationship between folder name and route.
I will suggest you to read the core routing to understand what is behind the scene.
I will recommend the Routing chapter of following books,
Professional ASP.NET MVC(Rob Conery,...), Pro ASP.NET MVC(Steve Sanderson), Programming Microsoft ASP.NET MVC (Dino Espatio)
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
gameover
0 Points
3 Posts
MVC 2.0 areas and routing
May 15, 2010 06:26 PM|LINK
Amigos,
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':
using System.Web.Mvc; namespace FirstSolution.Web.Controllers.Admin { public class AdminAreaRegistration : AreaRegistration { public override string AreaName { get { return "Admin"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = "" }, new string[] { "FirstSolution.Web.Controllers.Admin" } ); } } }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':
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" } ); } } }But I can't link to 'Admin/Blog' subfolders. For example when attempting to link to 'Admin/Blog/Posts' via Html.ActionLink("Admin/Blog/Posts", "Index", "Posts", new { area = "Admin/Blog" }, null) I receive a "resource can not be found" 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.
Nick_Uk
Participant
800 Points
445 Posts
Re: MVC 2.0 areas and routing
May 15, 2010 09:43 PM|LINK
Any chance you could post up the file hierarchy for your solution (relevant to the admin area)?
Site
Blog
gameover
0 Points
3 Posts
Re: MVC 2.0 areas and routing
May 15, 2010 10:02 PM|LINK
Hey Nick. Thanks for the reply! Below is the file hierarchy. Let me know if you need any more information.
Admin
Admin/Blog
Admin/Blog/Posts
Admin/Blog/Posts/Index.aspx
Admin/Dashboard
Admin/Dashboard/Index.aspx
Admin/Newsletters
Admin/Newsletters/Index.aspx
Admin/Shared
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:
context.MapRoute( null, "Admin/Blog/{controller}/{action}/{id}", new { action = "Index", id = "" }, new string[] { "FirstSolution.Web.Controllers.Admin.Blog" } );But I have been unsuccessful in creating the proper route.
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: MVC 2.0 areas and routing
May 16, 2010 02:47 AM|LINK
you are thinking in a wrong diection. First of all, In routing there is no one to one relationship between folder name and route.
I will suggest you to read the core routing to understand what is behind the scene.
I will recommend the Routing chapter of following books,
Professional ASP.NET MVC(Rob Conery,...), Pro ASP.NET MVC(Steve Sanderson), Programming Microsoft ASP.NET MVC (Dino Espatio)
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
gameover
0 Points
3 Posts
Re: MVC 2.0 areas and routing
May 18, 2010 02:20 AM|LINK
Thank you for the recommendations.
I was able to resolve my issue. I removed the "Blog" area and created a custom route within the "Admin" area to manage the 'Blog'.