Route Attribute on Action
[Route("Sports/{category}")]
public ActionResult SomeAction(string category)
{
ViewBag.category = category;
return View();
}
[Route("Sports/{category}/edit")]
public ActionResult SomeMoreAction(string category)
{
ViewBag.category = category;
return View();
}
Route Attribute on Controller or Route Prefix
Route Prefix can be applied on controller to avoid repeating same prefix on all actions.
[RoutePrefix("Sports")]
public class HomeController : Controller
{
[Route("{category}")]
public ActionResult SomeAction(string category)
{
ViewBag.category = category;
return View();
}
[Route("{category}/edit")]
public ActionResult SomeMoreAction(string category)
{
ViewBag.category = category;
return View();
}
}
Note: The RoutePrefix should not Start or End With a “/”