我们可以在 Asp.net MVC 应用程序的 URL 中仅使用控制器名称和 id 参数吗
假设我有一个名为 category 的控制器,其操作方法 Index 接受 id 作为参数。
因此,URL 如下所示:category/Index/foo。正如您所看到的,索引部分似乎不太正确。像这样的 URL:category/foo 将更容易阅读和理解。
就像在SO中一样,这些人使用:question/857344
我怎样才能实现这样的URL。在我的路由中,我为所有三个设置了默认值:控制器、操作和 ID。但是,当我尝试访问 category/foo 时,我收到“404 - 资源未找到”
Suppose, I have a controller named category with an action method, Index which takes id as parameter.
Therefore, the URL appears like this : category/Index/foo. As you can see, the Index segment just doesn't seem right. A URL such as this : category/foo will be more readable and understandable.
Just like in SO, these guys use : question/857344
How can I achieve such a URL. In my routes, I have set defaults for all three : controller, action and id. But, when i try to visit category/foo, I get the "404 - resource not find"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其映射为您想要的外观,然后指定操作。
还要确保将其放在默认路由之前
You map it how you want it to look then specify the Action.
Also make sure you put it before the default route