简体   繁体   中英

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).

The problem is, that when I access http://LocalHost:82/Ajax , I get The resource cannot be found . When I access http://LocalHost:82/Ajax/Index , it works.

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. 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? If not, this makes sense as your default action is NewRequests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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