I ask a similar question here I think this is a really easy one (of course not for me). I have a extension method for Html helper and I need to get current view's url with HtmlHelper. Does anyone have any idea about it?
相关问题
- MVC-Routing,Why i can not ignore defaults,The matc
- Entity Framework throws exception - Network Relate
- parameters in routing do not work MVC 3
- Slow loading first page - ASP.NET MVC
- There is no ViewData item with the key 'taskTy
相关文章
- “Dynamic operations can only be performed in homog
- How to get a list of connected clients on SignalR
- How do you redirect to the calling page in ASP.NET
- Change color of bars depending on value in Highcha
- The program '[4432] iisexpress.exe' has ex
- ASP.Net MVC 4 Bundles
- How to get server path of physical path ?
- Cannot implicitly convert Web.Http.Results.JsonRes
If you just want the requested url then you can just get it via the
Request.Url
object. This returns a Uri, but if you want the raw url thenRequest.RawUrl
.You could use the Request.RawUrl property or Request.Url.ToString() or Request.Url.AbsoluteUri.
You can use a Html Helper passing the object page as reference, like this:
An in the View just use:
Based on your comment and the original thread you linked to I think you want to use a Url helper to get the URL for the form action, but I could have misunderstood what you wanted:
In a View:
In a HTML Helper:
if you want to get information about the route information , like the controller or action method that are called
you can access the
RouteData
dictionary from theViewContext
Objectwill be like this
with the
RouteData
Dictionary you can get all the info needed about the controller , action and extra parameters' name , depending on what you want