WebAPI的屬性和相關操作 FormBody和 FormUri等
阿新 • • 發佈:2020-09-09
1.FromUri使用
將資料通過url方式傳遞。我們需要在webapi方法標明,這個引數只接受url中引數的值,
$(
"#Save"
).click(
function
() {
$.ajax({
url:
'http://localhost:21162/api/person/?str1=1&str2=3'
,
type:
'Get'
,
dataType:
'json'
,
success:
function
(data, textStatus, xhr) {
console.log(data);
},
error:
function
(xhr, textStatus, errorThrown) {
console.log(
'Error in Operation'
);
}
});
});
public IEnumerable<Person> GetAllPerson([FromUri] string str1, [FromUri] string str2)
{
return new List<Person>() {
new Person() {ID= "1" , Name= "李鴻章ALL" ,Age=15},
new Person() {ID= "2" , Name= "楊玉紅ALL" ,Age=15} };
}
|