0

User という名前のエリアがあり、そのために MapRoute を書きます。

  context.MapRoute(
      "User_Category",
      "User/Category/{categoryId}",
       new { controller = "Product", action = "Category", categoryId = UrlParameter.Optional },
       new { categoryId = @"\d+" }
  );

これは他の例です。リンクがあります:

<%=Html.ActionLink("Điện thoại", "Category", new { area = "User", controller = "Product", id = 1  }, null) %>
(http://localhost:8578/User/Product/Category/1)

確かに、私はこれを行うことはできません:

<%=Html.ActionLink("Điện thoại", "User/Category", new { area = "User", controller = "Product", id = 1  }, null) %>

上記の MapRoute に続いて、変更されています。エリア内にあることを意味します。エリア名を ActionLink に渡して次のようにする方法がわかりません。http://localhost:8587/User/Category/1

しかし、私が欲しいのは、ActionLinkをRouteUrlに置き換えて、次のような絶対リンクを取得することです**http://localhost:8587/User/Category/1**

私は何をすべきか?また、URL のユーザー名を削除するにはどうすればよいですか? 見てくれてありがとう!

4

1 に答える 1

1

ルートがルートパラメーターで定義されているためだと思いますcategoryIdが、アクションリンクは単にパラメーターを使用していますidか? もしそうなら、代わりにこれを試してください:

<%=Html.ActionLink("Điện thoại", "Category", new { area = "User", controller = "Product", categoryId= 1  }, null) %>

完全な絶対 URL が必要な場合は、次のようにします。

<a href="<%= Html.ViewContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority) + Url.Action("Category", new { area = "User", controller = "Product", categoryId= 1  }) %>">Điện thoại</a>
于 2013-04-16T17:07:38.867 に答える