【问题标题】:asp.net mvc wrong routing handleasp.net mvc错误的路由句柄
【发布时间】:2012-11-11 15:47:34
【问题描述】:

在 asp net mvc 中处理错误 url 路由的最佳实践是什么?

示例代码:

public ActionResult EditUser(int userId)
{
  ....
}
  1. ActionResult EditUser(int userId = 0) //默认参数并返回404
  2. ActionResult EditUser(int?userId) // 可以为空的参数并返回404
  3. ActionResult EditUser(int userId) // mvc 异常

谢谢

【问题讨论】:

    标签: asp.net-mvc error-handling asp.net-mvc-routing


    【解决方案1】:

    我使用了与这个线程非常相似的东西,它似乎捕捉到了我扔给它的所有东西,正确地显示了 URL 并返回了正确的响应代码。

    阅读这个答案,

    https://stackoverflow.com/a/2577095/1538039

    【讨论】:

    • 感谢链接 :) 但是这个答案仍然没有解决我的问题。在操作中没有在 url 中声明 id 的 EditUser(int userId),mvc throw expcetion...
    猜你喜欢
    • 2016-07-30
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-08
    • 2020-04-04
    相关资源
    最近更新 更多