routes.MapRoute(
name: "XX",
url: "{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional}
);
This won't make id required. Take a look at a similar questions here:
Question
I want to create a routing for this type of URL
where the last part is some kind of ID that is passed to HomeController index
public class HomeController : Controller
{
public ActionResult Index(string id)
{
return View();
}
}
i tried something like
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "XX",
url: "Home/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
but its not working.. Can someone help me with this matter? thanks in advance
La solution
routes.MapRoute(
name: "XX",
url: "{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional}
);
This won't make id required. Take a look at a similar questions here: