I'm building my first Asp.Net MVC2 Site, and i'm now trying to add an /Admin area to the site.
I don't want this area to be visibile to the main set of users so will only be accessible when you enter http://Intranet/Admin
What I have is a NewsController for my regular users but I also want an Admin NewsController and I'm not sure how to setup the Class hierarchy and folders so that when I add the Views they are in the correct location.
Inside my Global.Asax.cs I've added and the routes resolve correctly.
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Intranet.Controllers" }
);
routes.MapRoute(
"Admin", // Route name
"Admin/{controller}/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
new string[] { "Intranet.Controllers.Admin" }
);
And in the folder hierarchy I've setup
Views/
Admin/
News/
...I want the new view to go here...
In the Controllers
Controllers/
Admin/
AdminController.cs
NewsController.cs (this is the one i want for administration)
NewsController.cs (this is the regular one for viewing the list, specific item etc)
The problem I face is when I go into the admin/NewsController.cs on Index and Add View it tries to create it at the /News/Index.aspx rather than /Admin/News/Index.aspx.
This is the code for my admin news controller Controllers/Admin->Add->Controller
namespace Intranet.Controllers.Admin
{
public class NewsController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
Is there something I'm doing incorrectly, or what should I change so that when I add the views they are being created in the /Admin/{area} directory.