There is an Operation controller for it with the routing attribute set [RoutePrefix] , it has a GetOperationList method with the routing attribute set [Route] and the [ActionName] attribute

 [RoutePrefix("Operation/{operationId}")] public class OperationController: Controller { [Route("~/Operations"), ActionName("Index")] public ActionResult GetOperationList(){} } 

links generated by Html.ActionLink and Url.Action look like /Operations

 routes.MapRoute( name: "Default", url: "{не пойму как должна выглядеть строка адреса }" ); 

I tried to set the url as /Operations I get Exception

The route URL can not start with a '/' or '~' character and it can not contain a '? character. Parameter name: routeUrl

Tell me how the url string should look for the default route to the Index method of the Operation controller

When trying to open a website:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. Resource dependencies (can be removed), temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /

Version Information: Microsoft .NET Framework Version: 4.0.30319; ASP.NET Version: 4.6.1055.0


the addition of the additional attribute [Route(/~)] seems to have helped, but I am not sure of the correctness of this method

  • Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky

1 answer 1

no matter how strange it was, adding one more routing attribute to the GetOperationList method GetOperationList :

 [Route("~/")] [Route("~/Operations")] [ActionName("Index")] [AllowAnonymous] public ActionResult GetOperationList() { var model = _operationService2.GetOperationList(); return View("OperationList", model); } 

somewhere in RouteConfig

 routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Operation", action = "Index", id = UrlParameter.Optional } );