Hi I am trying to define a routing path for my URL.This is what it looks like so far:
routes.MapRoute(
name: "Category",
url: "{controller}/DisplayBooksByCategory/{categoryId}/{pageNumber}",
defaults: new { controller = "Home", action = "DisplayBooksByCategory" }
);
This works but it is not exactly what I want.At the moment my url looks something like this:
http://localhost:51208/Home/DisplayBooksByCategory/7/1
What I want is to be able to replace the categoryId with the actual category name.The category name is not passed as a parameter to the action only the categoryId.This is my action:
public ActionResult DisplayBooksByCategory(int pageNumber, int categoryId)
{
int bookByCategoryCount = bookRepository.CountBooksByCategory(categoryId);
var entities = new BooksAndCategories
{
Books = bookRepository.GetBookByCategory(categoryId, pageNumber, numberOfBooksOnPage),
PageNumber = pageNumber,
LastPageNumber = (bookByCategoryCount / numberOfBooksOnPage) + 1,
NumberOfBooksPerPage = numberOfBooksOnPage,
Categories = categoryRepository.GetCategories(),
CurentPage = "ProductManager",
CurentCategory = categoryId
};
return View("DisplayBooksByCategory", entities);
}
Is there any way to do that using the routing API without the need to modify the action?