c# - Get url for action in controller with attribute routing -
i have action in controller asp.net mvc 5 attribute routing.
[routeprefix("controllername")] public class mycontroller : controller { [route("actionname")] public actionresult index() { return view(); } } when try url in action (controller.url)
url.action("index", "my") i
/my/index
when same in view (it's webviewpage.url),
@url.action("index", "my") i
/controllername/actionname
how can /controllername/actionname in action?
if want construct url other controllers, need make use of urlhelper class this:
var urlhelper = new urlhelper(controllercontext.requestcontext); var url = urlhelper.action("index", "my"); this construct desired result: /controllername/actionname
Comments
Post a Comment