I would like my app to behave like the following:
Url = http://mydomain/one-of-my-blog-title -> Controller = Article -> Action = Index
The Index method in the controller would like like this:
public ActionResult Index(string title)
{
var article = GetArticle(title);
return View(article);
}
I configured my routes this way:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Article",
url: "{title}",
defaults: new { controller = "Article", action = "Index" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
The problem is when I to navigate to the ContactController's index method:
It tries to find the article where title == "contact"
I know I could use a route like "mydomain/articles/{title}" but I would really like to avoid this..