Given the action public IActionResult Get(int id), and no other attributes, where will the model binder look for the value of id by default?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi thực hiện hành động Get với phương thức public IActionResult Get(int id), và không có bất kỳ thuộc tính nào khác, thì bộ gắn model sẽ tìm kiếm giá trị của id theo mặc định ở đâu? Bộ gắn model sẽ tìm kiếm giá trị của id ở dữ liệu route (dữ liệu đường dẫn), sau đó là query string (dữ liệu tham số trong URL), và cuối cùng là dữ liệu form (dữ liệu được gửi qua form). Điều này là do ASP.NET Core sử dụng một bộ gắn model mặc định để gắn giá trị vào các thuộc tính của controller. Bộ gắn model này sẽ ưu tiên tìm kiếm giá trị trong dữ liệu route, sau đó là query string, và cuối cùng là dữ liệu form. Điều này giúp cho việc gắn model trở nên dễ dàng và linh hoạt hơn.
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