[英]ASP.NET MVC 2 - How to write RouteUrl with Url property in context.MapRoute modified?
我有一个名为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**
绝对链接
我该怎么办? 以及如何删除网址中的用户名? 感谢收看!
我认为这是因为您的路由是使用route参数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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.