I am using mvc 5.2.3 on 4.5.1 and want these urls
- /Nike/Shoes
- /Nike/Shoes/Running
- /Nike/Shirts/2002342345
- /Nike/Shoes/Running/98765432234
My controller has:
[HttpGet]
[Route("{brand}/{category}/{subcategory}/{page:int?}", Name="ProductIndex")]
public ActionResult Index(string brand, string category, int? page, string subcategory = "")
and gives /Nike/Shoes/Running but no /Nike/Shoes but /Products?brand=Nike&category=Shoes
When I add
[HttpGet]
[Route("{brand}/{category}/{page:int?}")]
public ActionResult Index(string brand, string category, int? page)
/Nike/Shoes/ works, but I also have /Nike/Shoes/?subcategory=Running
and my details method:
[HttpGet]
[Route("{brand}/{category}/{subcategory}/{productid:int:min(9000)}", Name="ProductDetails")]
public ActionResult Details(int productid)
gives:
The current request is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index(System.String, System.String, System.Nullable`1[System.Int32], System.String) on type shopmvc.Controllers.ProductsController System.Web.Mvc.ActionResult Index(shopmvc.ViewModels.ProductsViewModel) on type shopmvc.Controllers.ProductsController System.Web.Mvc.ActionResult Details(Int32) on type shopmvc.Controllers.ProductsController
So there is something wrong with my product link and category/subcategory routes. or with the way I try to reach it:
<a href="@Url.RouteUrl("ProductDetails", new { brand = item.Brand, category = item.Category, subcategory = item.SubCategory, productid = item.ID })">test</a>
<a href="@Url.Action("Details", "Products", new { brand = item.Brand, category = item.Category, subcategory = item.SubCategory, productid = item.ID })">
<a href="@Url.Action("Index", "Products", new { brand = c.Brand, category = c.Category, subcategory = c.SubCategory })">@c.DisplayName</a>