Calling Web API from MVC controller

前端 未结 5 1264
余生分开走
余生分开走 2021-02-01 03:37

I have a WebAPI Controller within my MVC5 project solution. The WebAPI has a method which returns all files in a specific folder as a Json list:

[{\"name\":\"file

5条回答
  •  清歌不尽
    2021-02-01 04:21

    Why don't you simply move the code you have in the ApiController calls - DocumentsController to a class that you can call from both your HomeController and DocumentController. Pull this out into a class you call from both controllers. This stuff in your question:

    // All code to find the files are here and is working perfectly...

    It doesn't make sense to call a API Controller from another controller on the same website.

    This will also simplify the code when you come back to it in the future you will have one common class for finding the files and doing that logic there...

提交回复
热议问题