I have 3 links on my website that are generated like below using url.action()
<a href="/ViewAd/421/Honda-Accord-2.4-Executive-Automatic" >
<a href="/ViewAd/420/Renault-Sandero-900t-Dynamique" >
<a href="/ViewAd/419/Audi-Rs5-2.9-Tfsi-Quattro-Tiptronic" >
As you can see, the links are exactly the same except for the IDs and the descriptions that are different. Oddly the only one that works properly is the 2nd ad, if I click on the 1st or the 3rd ad the request fails with a 404 error, also while debugging locally the 1st and 3rd ads don't even hit the breakpoint on my controller action as per below. What could be the problem?
I have attribute routing enabled and this is what my controller action looks like
[Route("ViewAd/{adID}/{desc}")]
public ActionResult ViewSingleAd(int adID, string desc)
{
// Code removed for brevity
return View();
}
My RouteConfig.cs is as follows
namespace myApp
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Error",
url:"error/{action}/{id}",
defaults: new { controller = "Home", action = "Index"/*, id = ""*/ }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id =
UrlParameter.Optional }
);
}
}
}