By default, where does the model binder attempt to get the data for a complex type parameter (like a class or record) in an [ApiController] action?
4 phương ánCó giải thíchTrung bình
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi sử dụng [ApiController] trong ASP.NET Core, model binder sẽ cố gắng lấy dữ liệu cho tham số kiểu phức tạp (như một lớp hoặc bản ghi) từ đâu? Theo mặc định, model binder sẽ lấy dữ liệu từ cơ thể yêu cầu (request body). Điều này có nghĩa là dữ liệu sẽ được gửi qua trong nội dung của yêu cầu HTTP, thường là dưới dạng JSON hoặc XML. Điều này giúp cho việc truyền dữ liệu phức tạp trở nên dễ dàng hơn và giúp cho việc xử lý dữ liệu trở nên linh hoạt hơn. Tuy nhiên, người dùng cũng có thể sử dụng các thuộc tính khác nhau để chỉ định nguồn dữ liệu cho model binder, chẳng hạn như [FromBody], [FromQuery] hoặc [FromRoute].
Cùng chương 4
A controller action needs to return a "Not Found" response when a resource does not exist. Which of the following is the best way to achieve this? [HttpGet("{id}")] public ActionResult<Product> GetProduct(int id) { var product = _productService.GetById(id); if (product == null) { return ???; // What should be here? } return product; }Câu hỏiFor the route [HttpGet("users/{userId}/orders/{orderId}")], what are userId and orderId?Có lời giảiCâu hỏiGiven the action public IActionResult Get(int id), and no other attributes, where will the model binder look for the value of id by default?Có lời giảiCâu hỏiCả 19 câu của chủ đề19 câu