【发布时间】:2020-02-23 23:05:42
【问题描述】:
我开始搞乱端点路由和 url 翻译,但我认为我错过了一些东西。
我的解决方案是here
我从this blog post中的例子开始
在地址栏中写入 url 按预期工作,但我注意到锚标记根本不生成 url。
布局示例
@{
Dictionary<string, string> routePol = new Dictionary<string, string>();
routePol.Add("language", "pl");
routePol.Add("controller", "Home");
routePol.Add("action", "Index");
}
<a asp-all-route-data="routePol">Poland</a>
应该生成
<a href="test/pl/Home/Index">Poland<a>
结果
<a href >Poland<a>
主端点
app.UseEndpoints(endpoints =>
{
endpoints.MapDynamicControllerRoute<TranslationTransformer>(
"{language=pl}/{controller=orders}/{action=list}");
});
我不明白出了什么问题。我阅读了端点路由,当提供的值生成不存在的路由时,锚标记不会生成 url,但上面的路由应该是有效的。
如果可能的话,有没有办法调试如何验证路由或记录错误?
编辑:问题现已解决,感谢 Rena。 我更新了my solution 并进行了修复,并添加了一个有用的组件,用于使用路线值改变文化,希望这对遇到与我相同的问题的每个人都有用。
【问题讨论】:
-
对于如何调试路由验证或记录错误,您可以使用源代码进行调试。
标签: c# localization asp.net-core-mvc asp.net-mvc-routing