I am trying to create a custom route to handle a specific URL with several parameters. I added a new route definition to global.asax, but when I try to go to action, I get the error message "A type was not found that matches the controller named" Home ".
Can someone tell me where I am going wrong?
Global.asax:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "HomeDetails", routeTemplate: "Home/Detail/{articleId}/{articleVersion}", defaults: new { controller = "Home", action = "Detail", articleId = "0", articleVersion = "0.0" } ); //routes.MapHttpRoute( // name: "DefaultApi", // routeTemplate: "api/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } //); routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
Controller:
public class HomeController : Controller { public ViewResult Index() { return View(); } public ViewResult Detail(int articleId, decimal articleVersion) {
The url I'm trying to click will look like http://localhost/home/detail/1234/1.2
source share