以下是我在global.asax.cs中的路由定义:
routes.Add(
new NamedTypedRoute(
"feedback-en", RouteType.Regular, "{culture}/Feedback",
new RouteValueDictionary(
new
{
culture = "en",
controller = "Feedback",
action = "Index"
}
),
null,
new MultiLingualMvcRouteHandler()
)
);
routes.Add(
new NamedTypedRoute(
"feedback-sl", RouteType.Regular, "{culture}/Kontakt",
new RouteValueDictionary(
new
{
culture = "sl",
controller = "Feedback",
action = "Index"
}
),
null,
new MultiLingualMvcRouteHandler()
)
);
如果我在视图中执行此操作
<%: Html.ActionLink("sl", "feedback-sl")%> | <%: Html.ActionLink("en", "feedback-en")%>
构造的URL指向根站点(构造的链接中不包含控制器/操作信息)。
如果我在视图中执行此操作
<%: Html.RouteLink("sl", "feedback-sl")%> | <%: Html.RouteLink("en", "feedback-en")%>
发生异常:
"A route named 'feedback-sl' could not be found in the route collection.
Parameter name: name"
我的两个问题:
答案 0 :(得分:1)
Html.ActionLink扩展程序呈现链接到操作的锚元素。另一方面,Html.RouteLink扩展呈现了一个可以解析为操作方法,文件,文件夹或其他资源的锚元素。 RouteLink实际上并不像ActionLink那样采用ActionName和ControllerName字符串。从更多细节看一下参数的参数名称。这里的描述在MSDN / IntelliSense中写得不是很好。
可悲的是,我对第二个问题没有答案。