非常好用的Json
1 /// <summary>
2 /// 返回对应用户的部门信息
3 /// </summary>
4 /// <param name="value"></param>
5 /// <returns></returns>
6 public JsonResult GetOrg(string value)
7 {
8 try
9 {
10 value = System.Web.HttpUtility.UrlDecode(value);
11 Org orgInfo = _lazyOrgService.Value.GetOrgInfoByAccount(value);
12 if (orgInfo == null) throw new Exception();
13 var list = new List<AvailableTag>();
14 list.Add(new AvailableTag
15 {
16 value = orgInfo.Code,
17 name = orgInfo.Name,
18 });
19 return Json(list);
20 }
21 catch
22 {
23 return Json(new AvailableTag { value = "", name = "" });
24 }
25 }
26
27 }
28 /// <summary>
29 /// json返回用户部门信息过程使用,由GetOrg方法调用
30 /// </summary>
31 public class AvailableTag
32 {
33 public string name { get; set; }
34 public string value { get; set; }
35 }
1 function GetOrg(account)
2 {
3 //根据Account获取Org信息
4 $.ajax({
5 type: "post",
6 url: "@Url.Action("GetOrg", "Protocol")",
7 data: { "value": account },
8 success: function (message) {
9 $("#ORG_NAME").val(message[0].name);
10 $("#ORG_CODE").val(message[0].value);
11
12 }, dataType: "json"
13 });
14 }