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} };
}
|