JC *_*bbs 21 asp.net asp.net-mvc
我正在为ASP.NET MVC编写一个帮助方法,我需要调用Url.Content以获取上下文的适当URL.但是,为了创造一个新的UrlHelper()我需要获得当前RequestContext(System.Web.Routing.RequestContext确切地说),我不知道如何抓住它.谁知道?
小智 46
如果当前的IHttpHandler是MvcHandler,则可以使用
((MvcHandler)HttpContext.Current.Handler).RequestContext
Run Code Online (Sandbox Code Playgroud)
Mar*_*man 19
注意到这仍然没有答案.从MVC 1.0开始,您可以:
public static string NewHelperMethod(this HtmlHelper helper)
{
UrlHelper url = new UrlHelper(helper.ViewContext.RequestContext);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11768 次 |
| 最近记录: |