asp.net - Get the url without the name of the method that called it -


i try url of website plus current controller without method called it.

inside examplecontroller, examplemethod request.url.tostring()

=>http://localhost:51747/.../examplecontroller/examplemethod

i need

http://localhost:51747/.../examplecontroller

the solution use parse , remove after last slash, not sure if there method using server info.

your issue can solved using 1 of url.action html helper overloads. generate example url:

http://localhost:51747/.../examplecontroller

you need do:

@url.action("examplecontroller", "index", null, request.url.scheme) 

assuming using default asp.net mvc routing config.

in more detail, if action provide helper 1 set default in routeconfig, not specified in resulting url.

routes.maproute(     name: "default",     url: "{controller}/{action}/{id}",     defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); 

see action = "index" default? whatever have set there have use when generating url.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -