问题描述
我使用本教程从核心2.2开始 [],提交序列号并更改颜色但风格相同。
一切顺利,直到我想要过滤选择,所以我需要第二次(和第三次)GET。使用Postman我得到一个重复的GET错误
https:// localhost:44334 / api / userdetails?FleetID = 1
Startup.cs中没有路由
我尝试过:
控制器以
开头
[路线(api / [控制器])]
[ApiController]
public class UserDetailsController:ControllerBase
{
DAL.UserDetails dsUserDetails = new UserDetails();
[HttpGet]
public ActionResult< IEnumerable< UserDetailsDB>> GetUsers()
{
IEnumerable< UserDetailsDB> lResult = dsUserDetails.UserDetailsList();
返回lResult.ToList();
}
带有额外过滤器的第二个GET - 这个的装饰或GET的调用语法
[HttpGet]
public ActionResult< IEnumerable< UserDetailsDB>> GetUserForFleet([FromQuery] int FleetID)
{
IEnumerable< UserDetailsDB> lResult = dsUserDetails.UserDetailsForFleet(FleetID);
返回lResult.ToList();
}
I used this tutorial to start with core 2.2 Tutorial: Create a web API with ASP.NET Core MVC | Microsoft Docs[^], filed off the serial numbers and changed the colour but the same style.
All went well until I wanted to get a filtered selection so I need a second (and third) GET. Using Postman I get a duplicate GET error with https://localhost:44334/api/userdetails?FleetID=1
There is no routing in the Startup.cs
What I have tried:
Controller starts with
[Route("api/[controller]")] [ApiController] public class UserDetailsController : ControllerBase { DAL.UserDetails dsUserDetails = new UserDetails(); [HttpGet] public ActionResult<IEnumerable<UserDetailsDB>> GetUsers() { IEnumerable<UserDetailsDB> lResult = dsUserDetails.UserDetailsList(); return lResult.ToList(); }
Second GET with additional filter - what is the decoration for this or the calling syntax for the GET
[HttpGet] public ActionResult<IEnumerable<UserDetailsDB>> GetUserForFleet([FromQuery] int FleetID) { IEnumerable<UserDetailsDB> lResult = dsUserDetails.UserDetailsForFleet(FleetID); return lResult.ToList(); }
这篇关于Asp.net核心2.2多个获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!