In a controller decorated with [ApiController], what happens automatically if ModelState.IsValid is false?
4 phương ánCó giải thíchDễ
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi một controller được trang bị [ApiController], nếu ModelState.IsValid là false, điều gì sẽ xảy ra tự động? Điều này có nghĩa là khi bạn gửi một yêu cầu đến controller và dữ liệu yêu cầu không hợp lệ, hệ thống sẽ tự động trả về một phản hồi HTTP 400 Bad Request. Phản hồi này sẽ chứa chi tiết về các lỗi xác thực. Điều này giúp người dùng biết rõ về các lỗi mà họ đã mắc phải và có thể sửa đổi dữ liệu yêu cầu một cách chính xác. Ngoài ra, hệ thống cũng sẽ không thực hiện hành động nào khác, vì ModelState.IsValid là điều kiện tiên quyết để thực hiện hành động. Vì vậy, nếu ModelState.IsValid là false, hệ thống sẽ tự động trả về phản hồi HTTP 400 Bad Request và dừng lại.
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ỏiAccording to inference rules, any complex type parameter NOT registered in the DI container and NOT matching a route parameter will be inferred as coming from where?Có lời giảiCâu hỏiBy 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?Có lời giảiCâu hỏiCả 19 câu của chủ đề19 câu