path to controller action
It is no problem to use Html.ActionLink in a View to obtain the right path to a controller action. I am just wondering whether this is also possible in other layers (e.g. controller). I am asking this because I am generating an <ul>
recursively with some data access to rend开发者_运维百科er a 'link tree structure'. Thanks!
Christian
In the controller you can use UrlHelper to create url.
string html = string.Empty;
UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
string edit = url.Action(Constants.action_Edit, Constants.ctrl_myController, new { someId });
html += "<a href=\"" + edit + "\">Edit</a> ";
This would create a string with html link inside. In the example I use constants to give correct action and controller, but it could of course be a "normal" string.
Let me know if you need more scenarios
精彩评论