The controller for path was not found or does not implement IController

前端 未结 20 2483
一个人的身影
一个人的身影 2020-11-29 20:50

I have an MVC4 project with language selection:

  • en
  • nl
  • fr
  • de

1 main part with:

  • About
  • Common (fo
20条回答
  •  时光取名叫无心
    2020-11-29 21:31

    This could be because the path was wrong. So check the path and the spelling of the controller first. In my case, my controller was named CampsController, and the WebApiConfig.cs file had an extra path in it.

    Instead of: http://localhost:6600/Camps

    It was: http://localhost:6600/api/Camps

    I had not noticed the api word in the WebApiConfig.cs file:

    config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );
    

    Also it could be because the controller was incorrectly named. Here I called LayoutController, but should have called Layout instead:

    @Html.Action("GetCurrentUser", "LayoutController" })
    

    should be:

    @Html.Action("GetCurrentUser", "Layout")
    

    Another example, it could be because you have bad Route paths defined. Make sure your paths are correct. Example:

       [RoutePrefix("api/camps")]
       public class CampsController : ApiController
    
       [Route("{moniker}")]
       public async Task Get(string moniker)
    

提交回复
热议问题