LoginSignup
2
0

More than 5 years have passed since last update.

ASP.NET Core > IHttpActionResult vs IActionResult のどちらをつかえばいいのか?についてメモ

Last updated at Posted at 2019-03-27

以下リンク先に回答あり

c# - IHttpActionResult vs IActionResult - Stack Overflow

IActionResultは asp.net core
IHttpActionResultは、ASP.NET時代のものとの事

asp.net coreでは、IActionResultを使った方がよさそうです。

using System;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;


[HttpGet("{id}")]
[ProducesResponseType(typeof(Product), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public IActionResult GetById(int id)
{
    if (!_repository.TryGetProduct(id, out var product))
    {
        return NotFound();
    }

    return Ok(product);
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0