In my current project I needed to make a new .NET MVC controller that is passed a parameter. I want this new controller to use the same javascript files as the original home controller.
RouteConfig.cs
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Controller2",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Controller2", action = "Index", id = UrlParameter.Optional }
);
Here is the Controller2 code:
public class Controller2 : Controller
{
public ActionResult Index(int id)
{
//do stuff here
return View("~/Views/Home/Index.cshtml");
}
}
When I access Controller2 via this link: http://localhost/AppName/Controller2/index/1
The application navigates to the correct index file but looks for the css files in a location where they are not, namely: http://localhost/AppName/Controller2/index/dist/css/app.css
The files the index for Controller2 are really in:
http://localhost/AppName/dist/css/app.css
It must have something to do with my Routing but I can't figure it out.
How do I fix this problem?
Thanks, Matt