1. 程式人生 > 實用技巧 >WebAPI的屬性和相關操作 FormBody和 FormUri等

WebAPI的屬性和相關操作 FormBody和 FormUri等

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'); } }); });
publicIEnumerable<Person> GetAllPerson([FromUri]stringstr1, [FromUri]stringstr2) { returnnewList<Person>() { newPerson() {ID="1", Name="李鴻章ALL",Age=15}, newPerson() {ID="2", Name="楊玉紅ALL",Age=15} }; }