简体   繁体   English

C#MVC3-“找不到资源”

[英]C# MVC3 - “The resource cannot be found”

I am trying to create another controller for my Ajax handler - so now I have an AppController (The site controller) and an AjaxController (the Ajax request handler). 我正在尝试为我的Ajax处理程序创建另一个控制器-所以现在我有一个AppController(站点控制器)和一个AjaxController(Ajax请求处理程序)。

The problem is, that when I access http://LocalHost:82/Ajax , I get The resource cannot be found . 问题是,当我访问http:// LocalHost:82 / Ajax时 ,我得到The resource cannot be found When I access http://LocalHost:82/Ajax/Index , it works. 当我访问http:// LocalHost:82 / Ajax / Index时 ,它可以工作。

The problem is the default routing, right? 问题是默认路由,对吗? Here is my routing: 这是我的路线:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "App", action = "NewRequests", id = UrlParameter.Optional     } // Parameter defaults
        );

If you need more info dont hesitate to ask. 如果您需要更多信息,请随时询问。 Thanks! 谢谢!

Your routing: 您的路线:

routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "App", action = "NewRequests", id = UrlParameter.Optional     } // Parameter defaults
        );

Declares that default action is NewRequests, so it is expected that your AjaxController would have [HttpGet] NewRequests actions. 声明默认操作为NewRequests,因此预期您的AjaxController将具有[HttpGet] NewRequests操作。 You can do that by, 你可以这样做

[HttpGet]
public ActionResult NewRequests()
{
  // ...
}

or 要么

[HttpGet, ActionName("NewRequests")]
public ActionResult WhatEverNameOfActionYouLike()
{
  // ...
}

Is there an NewRequests method returning an ActionResult in the Ajax controller? Ajax控制器中是否有NewRequests方法返回ActionResult? If not, this makes sense as your default action is NewRequests. 如果没有,这是有道理的,因为您的默认操作是NewRequests。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM