Web API : Parameter Binding
Parameter Binding: Get Action Method with Primitive Parameter: Xem xét ví dụ về phương thức Get , phương thức này chứa tham số có kiểu dữ liệu nguyên thủy. Example: Primitive Parameter Binding public class StudentController : ApiController { public Student Get( int id) { } } Như bạn thấy phương thức Get chứa tham số id kiểu int. Vì vậy , Web API sẽ thử đính kèm giá trị id của câu truy vấn URL , sau đó chuyển đổi nó thành kiểu int và gán nó vào tham số id của phương thức Get . Ví dụ, nếu một request HTTP là http://localhost/api/student?id=1 thì giá trị của tham số id sẽ là 1. Sau đây là những request HTTP GET hợp lệ cho phương thức trên http://localhost/api/student?id=1 http://localhost/api/student?ID=1 Ghi chú: Tên tham số câu truy vấn và têm tham số của phương thức phải giống nhau . Nếu tên không giống nhau thì giá trị của tham số câu truy vấn sẽ không được gán. Thứ tự của tham số có thể khác nhau. Multiple Primitive
Nhận xét
Đăng nhận xét