Advantage of using IActionResult as result type in Actions

前端 未结 2 968
面向向阳花
面向向阳花 2021-01-01 11:31

What\'s the advantage or recommendation on using IActionResult as the return type of a WebApi controller instead of the actual type you want to return?

2条回答
  •  耶瑟儿~
    2021-01-01 12:38

    The main advantage is that you can easily test your code using a mocking framework.

    And as you build your controllers, you can easily change your return object as well. IActionResult is a interface and has many implementations like JsonResult, ViewResult, FileResult and so on.

提交回复
热议问题