路线未找到或构造不正确

[英]Routes not found or constructed incorrectly


The following is my routes definition from global.asax.cs:

以下是我在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()
  )
);

If I do this in the view

如果我在视图中这样做

<%: Html.ActionLink("sl", "feedback-sl")%> | <%: Html.ActionLink("en", "feedback-en")%>

the constructed URL points to the root site (no controller/action information is included in the constructed link).

构造的URL指向根站点(构造的链接中不包含控制器/操作信息)。

If I do this in the view

如果我在视图中这样做

<%: Html.RouteLink("sl", "feedback-sl")%> | <%: Html.RouteLink("en", "feedback-en")%>

an exception occurs:

发生异常:

"A route named 'feedback-sl' could not be found in the route collection.
Parameter name: name"

My two questions:

我的两个问题:

  1. Why are there two very similar helpers, RouteLink and ActionLink? What's the difference between them?
  2. 为什么有两个非常相似的助手,RouteLink和ActionLink?它们之间有什么区别?
  3. I guess there could be something wrong with my NamedTypedRoute implementation. I need this to have named routes and typed routes - route can be admin and regular. I use this information to dynamically construct administration menu based on routes definition. For administration pages, I have names pointing to resource strings and then I use those names in administration page titles. That way I have localizable route names. Am I overcomplicating this ??
  4. 我想我的NamedTypedRoute实现可能有问题。我需要这个有命名的路由和键​​入的路由 - 路由可以是管理员和常规路由。我使用此信息根据路由定义动态构建管理菜单。对于管理页面,我有指向资源字符串的名称,然后我在管理页面标题中使用这些名称。这样我就有了可本地化的路由名称。我是不是太复杂了?

1 个解决方案

#1


1  

Html.ActionLink extension renders an anchor element that links to an action. Html.RouteLink extension on the other hand renders an anchor element which could resolve to an action method, a file, a folder, or some other resource. The RouteLink doesn't really take ActionName and ControllerName strings like the ActionLink. From more detail look a bit at the parameter names for the parameters. The descriptions here are not really well written in MSDN/IntelliSense.

Html.ActionLink扩展程序呈现链接到操作的锚元素。另一方面,Html.RouteLink扩展呈现了一个可以解析为操作方法,文件,文件夹或其他资源的锚元素。 RouteLink实际上并不像ActionLink那样采用ActionName和ControllerName字符串。从更多细节看一下参数的参数名称。这里的描述在MSDN / IntelliSense中写得不是很好。

Sadly I don't have an answer for the second question.

可悲的是,我对第二个问题没有答案。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2010/11/15/e71f179fe1e9f2a3959dd8b625c3c021.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告