[英]How to solve flutter web api cors error only with dart code?
[英]How to solve multiple endpoints error in Web API
我在 API 的 controller 中有多個操作。 它們的意思是檢索一堆與模型相關的數據,所以它們都是[HttpGet]
類型的。 如何解決多個端點錯誤?
[HttpGet("{genreName}")]
public IActionResult GetMoviesByGenre(string genreName)
{
var movies = _applicationDbContext.Movies.Where(m => m.Genres.Any(g => g.Name == genreName)).ToList();
if (string.IsNullOrWhiteSpace(genreName))
return NotFound();
return Ok(movies);
}
[HttpGet("{directorName}")]
public IActionResult GetMoviesOfADirector(string directorName)
{
var movies = _applicationDbContext.Movies.Where(m => m.Director.Name.Contains(directorName)).ToList();
if (string.IsNullOrEmpty(directorName))
return NotFound();
return Ok(movies);
}
您可以嘗試創建兩個控制器,例如 DirectorController.cs 和 GenreController,並且您可以擁有如下端點:
api/導演/{directorName}/電影
api/流派/{流派名稱}/電影
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.