I need to use System.Web.Routing.RequestContext in a view model to call HtmlHelper.GenerateLink ().
Although theoretically you can write:
var rc = HttpContext.Current.Request.RequestContext;
in practice, you absolutely should not do something like this in the presentation model. What HTML helpers should do:
public static MvcHtmlString GenerateMyLink<MyViewModel>(this HtmlHelper<MyViewModel> html) { MyViewModel model = html.ViewData.Model; RequestContext rc = html.ViewContext.RequestContext;
and in your strongly typed view, MyViewModel is simple:
<%= Html.GenerateMyLink() %>
source share