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

在参数比较少情况下、或者Url长度小于256的情况下。可以考虑使用FromUri, 部分游览器会现在url大小,在这种情况下我们就要使用FromBody

2.FromBody

将数据通过post data方式方式传递。我们需要在webapi方法标明接受data参数,传递json参数


        $("#Save").click(function () {
$.ajax({
url: 'http://localhost:21162/api/person/',
type: 'Get',
dataType: 'json',
data: { "str1": "1", "str2": "2" },
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
});

3.ActionName使用,通过制定Action来调用方法

        [ActionName("GetAllPerson")]
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} };
}
      $("#Save").click(function () {
$.ajax({
url: 'http://localhost:21162/api/person/GetAllPerson?str1=1&str2=3',
type: 'Get',
dataType: 'json',
//data: { "str1": "1", "str2": "2" },
success: function (data, textStatus, xhr) {
console.log(data);
},
error: function (xhr, textStatus, errorThrown) {
console.log('Error in Operation');
}
});
});

4.NonAction  表示不被外部应用程序调用

5. [AcceptVerbs("GET","POST")]

        [ActionName("GetAllPerson")]  //指定ActionName
[NonAction] //不被外部应用程序调用
[AcceptVerbs("GET","POST")] //表示既可以Get请求,又可以Post请求
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} };
}

理解中WebAPI的属性和相关操作 FormBody和 FormUri等(WebAPI 二)的更多相关文章

  1. Web API与AJAX:理解FormBody和 FormUri的WebAPI中的属性

    这是这一系列文章"与 AJAX 的 Web API".在这一系列我们都解释消耗 Web API rest 风格的服务使用 jQuery ajax() 和其他方法的各种方法.您可以阅 ...

  2. python三大框架之一flask中cookie和session的相关操作

    状态保持 Cookie cookie 是指某些网站为了 辨别  用户身份,进行会话跟踪而储存在用户本地的数据(通常会经过加密),复数形式是 coolies. cookie是由服务器端生成,发送给客户端 ...

  3. 11G RAC 中 OCR 及Voting Disk 相关操作

    一.启动oracle clusterware先决条件:Oracle High Availability Services daemon(OHASD)运行在所有集群节点上1.启动整个Oracle Clu ...

  4. java-Eclipse中使用JDBC连接数据库及相关操作

    准备工作:mysql-connector-java-5.1.6-bin.jar配置 package com.job; import java.sql.Connection; import java.s ...

  5. Python3中的List列表的相关操作

    列表对象内建函数 1. append(obj) 在列表的末尾添加新元素obj.例: >>> a = ['a', 'b', 'c'] >>> a.append('d' ...

  6. JS中对象的定义及相关操作

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. set-cookie中的SameSite属性

    原文:set-cookie中的SameSite属性 再见,CSRF:讲解set-cookie中的SameSite属性 2016-04-14 13:18:42 来源:360安全播报 作者:暗羽喵 阅读: ...

  8. C# 对类中的保护成员进行写操作(邀请大家拍砖)

    假如我有一个类库 Lib,提供一个类 ClassA 对外服务,ClassA 中有若干只读属性 PropA, PropB 等等,外部调用者无法对 ClassA 中的 PropA 和 PropB 进行写操 ...

  9. 理解特性attribute 和 属性property的区别 及相关DOM操作总结

    查一下英语单词解释,两个都可以表示属性.但attribute倾向于解释为特质,而property倾向于解释私有的.这个property的私有解释可以更方便我们下面的理解. 第一部分:区别点 第一点:  ...

随机推荐

  1. chisel中pviews命令无法使用

    chisel是用Python写的LLDB调试器插件,用来调试iOS应用非常方便,相关下载安装链接如下:https://github.com/facebook/chisel.本人安装之后,在xcode里 ...

  2. git commit的--amend选项

    git commit --amend常常用来修改某个branch上最顶端的commit,大多数情况下,这个命令给人的感觉是用新的commit替换了原来的commit.git commit --amen ...

  3. SpringMvc项目 FastJson的数据中有$ref解决办法

    这是FastJson返回的数据,经过在线json格式转换工具转换的数据 阴影部分套用上面的dept(部门)信息,使用easyui只能获取第一行,凡是引用的都无法获取 经各种搜索: 推荐网址:http: ...

  4. C#读写word

    操作word之前需要在COM引入Microsoft Office 12.0 Object Library(文件库可能不一样) 然后添加using Microsoft.Office.Interop.Wo ...

  5. activiti笔记二:用户任务

    1, assignee 代替humanPerformer  功能 2, cadidateUsers代替potentialOwner功能 3, candidateGroups代替potentialOwn ...

  6. 海量数据面试题----分而治之/hash映射 + hash统计 + 堆/快速/归并排序

    1.从set/map谈到hashtable/hash_map/hash_set 稍后本文第二部分中将多次提到hash_map/hash_set,下面稍稍介绍下这些容器,以作为基础准备.一般来说,STL ...

  7. Find them, Catch them(POJ 1703 关系并查集)

    Find them, Catch them Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38668   Accepted: ...

  8. Material风格的Quick组件,妈妈再也不用担心我的界面不好看了

    https://github.com/papyros/qml-material http://www.zhihu.com/question/38523930

  9. C# Nullable可空类型

    一个Nullable类型就是基本类型加上一个"是否为null指示器"的合成类型.对于一个类型,如果既可以给他分配一个值,也可以给它分配null引用,我们就说这个类型是可空的. 可空 ...

  10. ISBN-10和ISBN-13有什么区别?

    ISBN扩升至13位 1. 现有ISBN的结构 国际标准书号ISBN是英文International Standard Book Number的缩写,1971年国际标准化组织ISO(Internati ...