Good day. I make a site on ASP.NET MVC 5. In View there is a button (form)
@using (Html.BeginForm("AddToCart", "Cart", FormMethod.Post)) { <div class="pull-right"> @Html.HiddenFor(b=> b.Id) @Html.Hidden("returnUrl", Request.Url.PathAndQuery) <input type="submit" class="btn btn-success" value="Добавить в корзину"/> </div> } Accordingly, it generates a POST request to the Cart controller, the AddToCart method. the problem is that when you click on the button, a routing error occurs and the AddToCart method is not called. ERROR: "The matched route value does not include a 'controller' route value, which is required."
Routing Settings
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // URL:"/" - Выводит первую страницу списка товаров всех категорий routes.MapRoute( name: null, url: "", defaults: new { controller = "Books", action = "List", page = 1, genre = (string)null } ); //URL: "/PageX" - Выводит страницу X, отображая товары всех категорий routes.MapRoute( name: null, url: "Page{page}", defaults: new { controller = "Books", action = "List", genre = (string)null }, constraints: new { page = @"\d+" } ); // URL:"/категория" - Отбражает первую страницу элементов указанной категории routes.MapRoute( name: null, url: "{genre}", defaults: new { controller = "Books", action = "List", page = 1 } ); // URL:"/категория/PageX" - Отбражает заданную страницу элементов указанной категории routes.MapRoute( name: null, url: "{genre}/Page{page}", defaults: new { controller = "Books", action = "List" }, constraints: new { page = @"\d+" } ); routes.MapRoute( name: null, url: "Nav/Menu" ); I did not register routes for this controller. Tell me how to make a universal route for such calls through the form?