【问题标题】:Http 404 Not Found in MVC Application在 MVC 应用程序中找不到 Http 404
【发布时间】:2014-02-13 10:54:17
【问题描述】:

我正在调用只有一个参数的控件。

 http://localhost:49809/Import/QBData/test



[ActionName("QBData")]
        public bool getconnection(string id)
        {
            return true;
        }

...它正在调用

但是下面的控件没有调用:总是它给出:Http 404 Not found...

我用过这个:

 http://localhost:49809/Import/Test/checking




 [ActionName("Test")]
        public bool Testing(string id)
        {
            return true;
        }

谁能告诉我......为什么它不打电话......

谢谢!

【问题讨论】:

  • 你能分享你的路线配置吗?
  • routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
  • @Havab,只有那个?!如果是这样,难怪它会爆炸:)

标签: asp.net-mvc model-view-controller


【解决方案1】:

您需要一条与您的操作相匹配的路线 - 这应该同时匹配。

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Import", action = "QBData", id = UrlParameter.Optional },
            namespaces: new string[1] { "Your.Namespace.Controllers" }
        );

另外,为什么不让你的动作方法命名为你想要的而不是使用动作名称属性呢?

【讨论】:

    【解决方案2】:

    我尝试根据您上面的代码创建一个包含名为 Import 的控制器和两个操作方法的 MVC 项目。

        [ActionName("QBData")]
        public bool getconnection(string id)
        {
            return true;
        }
    
        [ActionName("Test")]
        public bool Testing(string id)
        {
            return true;
        }
    

    在文件 RouteConfig.cs 我有以下代码

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    

    一切对我来说都很好,我在浏览器中对两个 URL 都得到了“真实”的响应。

    确保您的路由符合上述规定。

    【讨论】:

      猜你喜欢
      • 2017-12-29
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多