I have now implemented such images:

<a href='@Url.Action("ProductList", "Product", new { id = Model.ProductID })'> 

receiving method:

 public ActionResult ProductList(int id = 0) { var item = repository.Products.FirstOrDefault(x => x.ProductID == id); return View(item); } 

In this case, the address bar is shown for example as "imyasayta.ru/ id2 "

I want to do what the product name would show in place of id. If I do this image:

 <a href='@Url.Action("ProductList", "Product", new { name = Model.Name, })'> 

and method

 public ActionResult ProductList(string name) { var item = repository.Products.FirstOrDefault(x => x.Name == name); return View(item); } 

then I conflict with the sorting of products, sorting also takes a string

RouteConfig.cs

 routes.MapRoute(name: "Product", url: "id{id}", defaults: new { controller = "Product", action = "ProductList" } ); routes.MapRoute(null, "{category}", new { controller = "Product", action = "List", page = 1 } ); 

How to display the product name but in the method get the id?

I decided to see the source NopCommerce (where it happens)

 <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title"> 

receiving method

 public ActionResult ProductDetails(int productId, int updatecartitemid = 0) { .... return View(model.ProductTemplateViewPath, model); } 

but it is not possible how to achieve this? thank you in advance for your response.

  • I do not quite understand what you mean by конфликтует с сортировкой продуктов ? - Adam
  • in "RouteConfig.cs" is the second MapRoute to sort products by category. When I click on links with sorting it goes along the first MapRoute. In a word, I can not separate both according to different MapRoute. - Laziz Ergashev
  • I need, for example, "sayt.ru/ImyaProdukta" and "sayt.ru/SortirovkaPoKolichestvu" were distributed among different MapRoute-am - Laziz Ergashev
  • I do not quite understand: why for such a task is flattering маршрутизацию ? I thought you had to hide the id for safety. - Adam
  • Well, you also need to hide for beauty. And how to do that if not the routing? - Laziz Ergashev

0