1

使用该ViewPath属性时,我注意到它返回的大小写与在 URL 中键入的大小写相同。例如,如果我的视图设置为,当有人在浏览器中Views/Some/Path键入时,将返回而不是./some/pathViewPath~/Views/some/path~/Views/Some/Path

任何想法如何正确大写该信息?我真的只需要知道正在渲染的视图,所以只要我能找到正确的视图路径,我就可以接受其他想法。

4

1 回答 1

1

System.Web.Routing.Route您可以根据将路径转换为标题大小写来编写自己的路线;像这样:

public class LowercaseRoute : System.Web.Routing.Route
{
public LowercaseRoute(string url, IRouteHandler routeHandler) 
    : base(url, routeHandler) { }
public LowercaseRoute(string url, RouteValueDictionary defaults, IRouteHandler routeHandler) 
    : base(url, defaults, routeHandler) { }
public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, IRouteHandler routeHandler) 
    : base(url, defaults, constraints, routeHandler) { }
public LowercaseRoute(string url, RouteValueDictionary defaults, RouteValueDictionary constraints, RouteValueDictionary dataTokens, IRouteHandler routeHandler) 
    : base(url, defaults, constraints, dataTokens, routeHandler) { }

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
    VirtualPathData path = base.GetVirtualPath(requestContext, values);
    TextInfo ti = new CultureInfo("en-US",false).TextInfo;

    if (path != null)
        path.VirtualPath = ti.ToTitleCase(path.VirtualPath);

    return path;
}
}

从这里的想法。

于 2013-07-10T00:35:25.643 回答