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.
конфликтует с сортировкой продуктов? - Adamмаршрутизацию? I thought you had to hide theidfor safety. - Adam