通过路由调整地址栏中显示的 URL
我想优化网络浏览器中显示的 URL。我知道路由非常适合,但我不知道它是否可以按照我想要的方式进行。我有一个列表中的项目列表。每个项目都有一个 ID、名称和类别。导航到详细产品页面时,显示的 URL 应为“/category/name”。我知道我可以在 ActionLink 中传递 ID、类别和名称,并在 Global.asax 中调整路由。我已经这样做了,但我仍然拥有与 URL 其余部分连接的 ID。这太丑了。
这是一个示例:
我认为的 ActionLink:
@Html.ActionLink(@p.Name, "Detail", new { projectID = @p.ProjectID, category = @p.Category, name = @p.Name })
Global.asax:
routes.MapRoute(null,
"{category}/{name}",
new { controller = "Project", action = "Detail" }
);
生成的 URL:
,projectID 始终添加到 URL 的末尾。我怎样才能避免这种行为?
谢谢。
I would like to optimize my URL showed in web browsers. I know Routing is perfect for that but I don't know if it is possible the way I want. I have a list of projects in a list. Each project have an ID, a name and a category. When navigating to the detail product page, the URL showed should be "/category/name". I know I can pass the ID, the category and the name in the ActionLink and adjusting the routing in Global.asax. I already do that but I still have the ID which is concatenate to the rest of the URL. This is ugly.
Here is an example:
The ActionLink in my view:
@Html.ActionLink(@p.Name, "Detail", new { projectID = @p.ProjectID, category = @p.Category, name = @p.Name })
the Global.asax:
routes.MapRoute(null,
"{category}/{name}",
new { controller = "Project", action = "Detail" }
);
The resulting URL:
As you can see, the projectID is always added to the end of the URL. How can I avoid that behaviour?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
);
会给你的
是你想要的吗?
);
will give you
is that what you want ?