I'm working on an Asp.Net Core 3.1 MVC project and want to change some controllers and actions name in url. Almost all of answers is related to .net core API or mvc (without .net core) but I want to do it in Asp.Net Core Mvc application.
For example, The controller:
public class ProductCategoriesController : Controller
{
private readonly DBContext _context;
public async Task<IActionResult> Details(int? id)
{
// Some Codes ...
}
}
What I want to do is when I call the action "Details", the url goes to be like (http://domain/product-category/power-tools) which "power tools" is one of categories but as common in Asp.Net Core MVC it is (http://domain/ProductCategories/Details/1).
I tried to change controller prefix name and Action name but it doesn't work. I also tried to define new route endpoint in startup such as below but neither it works.
endpoints.MapControllerRoute(
name: "category",
pattern: "product-category/{*title}",
defaults: new { controller = "ProductCategories", action = "Details" });
Is it possible to change action names and controller name without using Api controllers? How do I do that? Thanks