gpt4 book ai didi

.net - 强制 ActionLinks 呈现为小写

转载 作者:行者123 更新时间:2023-12-04 07:14:55 27 4
gpt4 key购买 nike

没有创建我自己的 ActionLink HtmlHelper 有没有办法强制任何 ActionLinks 呈现小写?

更新:
查看以下链接以扩展 RouteCollection 以添加 LowecaseRoutes
[ http://www.makiwa.com/index.php/2008/05/31/lowercase-mvc-route-urls/]
[ http://goneale.wordpress.com/2008/12/19/lowercase-route-urls-in-aspnet-mvc/]

更新 - 2011 年 2 月 3 日:
由于上面的两个链接现在不再工作,我已经用我的解决方案发了一个帖子

http://blog.lukesmith.net/2009/02/01/generating-and-enforcing-that-any-link-and-request-is-lowercase-with-aspnet-mvc/

最佳答案

处理此问题的最佳方法是在路由级别。强制所有路由路径为小写,它将正确传播到您的操作链接等。

我解决这个问题的方法是创建一个继承 Route 的新路由类。并简单地覆盖 GetVirtualPath方法;

public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
var virtualPath = base.GetVirtualPath(requestContext, values);

if (virtualPath != null)
virtualPath.VirtualPath = virtualPath.VirtualPath.ToLowerInvariant();

return virtualPath;
}

我还为 RouteCollection 创建了一些扩展方法以便于使用这个新的路由类。

关于.net - 强制 ActionLinks 呈现为小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/495006/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com