.net - 自定义路由 ASP.NET MVC 在每个 Controller 中设置默认操作

标签 .net asp.net asp.net-mvc asp.net-mvc-routing

如何定义它链接到默认操作的路由。

例如,

/Customer/acme-company

/Client/bill-johnson

总是在 Controller 客户端和客户中寻找方法获取。

最佳答案

使用参数默认值。

routes.MapRoute(
    "MyRoute",                                   // Route name
    "{controller}/{someParameter}",              // URL with parameters
    new { controller = "Home", action = "Get" }  // Parameter defaults
);

关于.net - 自定义路由 ASP.NET MVC 在每个 Controller 中设置默认操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5883152/

相关文章:

.net - 编译 C# → LLVM → ASM.JS?

.net - 具有属性继承的表达式树导致参数异常

.net - 使 3D 模型透明

c# - 我如何以指数方式表示 c# 图表轴值?

asp.net - 如何在azure虚拟机中部署asp.net webapp

asp.net-mvc - MVC 中的 Kendo UI 网格,带有条件自定义命令按钮

c# - 为什么我预期的空对象不为空?

.net - 使用存储库模式的 Entity Framework 缓存

asp.net - .Net System.Mail.Message添加多个 "To"地址

asp.net-mvc - MVC3 如何禁用/启用 ActionLink