Forcing ActionLinks to be rendered as lowercase

后端 未结 1 1643
天涯浪人
天涯浪人 2021-02-06 05:47

Without creating my own ActionLink HtmlHelper is there a way to force any ActionLinks to be rendered lowercase?

Update: Check out the following links fo

相关标签:
1条回答
  • 2021-02-06 06:28

    The best way to handle this, is at the routing level. Force all route paths to be lowercase, and it will properly propagate to your action links etc.

    The way I've solved this, is to create a new route class that inherits Route and simply overrides the GetVirtualPath method;

    public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
    {
        var virtualPath = base.GetVirtualPath(requestContext, values);
    
        if (virtualPath != null)
            virtualPath.VirtualPath = virtualPath.VirtualPath.ToLowerInvariant();
    
        return virtualPath;
    }
    

    I've also created a few extension methods for RouteCollection to make it easy to use this new route class.

    0 讨论(0)
提交回复
热议问题