不知道是不是你要的那种,这是用于返回简单数据表达数据操作成功,中间复杂代码掠过看首尾

  1. [HttpPost]
  2. public IActionResult DataRole(int id, string[] complay_arry, string[] site_arry, string[] equipment_arry)
  3. {
  4. var message = "修改失败!";
  5. int success = ;
  6. try
  7. {
  8. using (var transaction = _session.BeginTransaction())
  9. {
  10.  
  11. for (int i = ; i < complay_arry.Length; i++)
  12. {
  13. for (int j = ; j < site_arry.Length; j++)
  14. {
  15. for (int k = ; k < equipment_arry.Length; k++)
  16. {
  17. var role = _session.QueryOver<RoleDevicePermission>().Where(m => m.Device.Id == equipment_arry[k]).List();
  18. RoleDevicePermission roles = null;
  19. if (role.Count == )
  20. {
  21. roles = new RoleDevicePermission();
  22. Device d = _session.Get<Device>(equipment_arry[k]);
  23. if (d.Building.Id == site_arry[j] && d.Organization.Id == complay_arry[i])
  24. {
  25. DateTime time = DateTime.Now;
  26. Organization rogin = null;
  27. rogin = _session.Get<Organization>(complay_arry[i]);
  28. Building building = _session.Get<Building>(site_arry[j]);
  29. Role r = _session.Get<Role>(id);
  30. roles.Organization = rogin;
  31. roles.Building = building;
  32. roles.Device = d;
  33. roles.Role = r;
  34. roles.IncludeAllBuilding = true;
  35. roles.CreatedAt = time;
  36. _session.Save(roles);
  37. if (i % == )
  38. {
  39. _session.Flush();
  40. _session.Clear();
  41. }
  42. message = "修改成功!";
  43. }
  44. }
  45. else
  46. {
  47. roles = role[];
  48. Device d = _session.Get<Device>(equipment_arry[k]);
  49. if (d.Building.Id == site_arry[j] && d.Organization.Id == complay_arry[i])
  50. {
  51. DateTime time = DateTime.Now;
  52. Organization rogin = null;
  53. rogin = _session.Get<Organization>(complay_arry[i]);
  54. Building building = _session.Get<Building>(site_arry[j]);
  55. Role r = _session.Get<Role>(id);
  56. roles.Organization = rogin;
  57. roles.Building = building;
  58. roles.Device = d;
  59. roles.Role = r;
  60. roles.IncludeAllBuilding = true;
  61. roles.CreatedAt = time;
  62. _session.Update(roles);
  63.  
  64. message = "修改成功!";
  65. }
  66. }
  67. }
  68. }
  69. }
  70. transaction.Commit();
  71. success = ;
  72. }
  73. }
  74. catch (Exception)
  75. {
  76.  
  77. message = "修改失败!";
  78. }
  79.  
  80. return Json(new { success, message });
  81. }

在视图接收

  1. $.ajax({
  2. type: "post",//提交方式
  3. data: { complay_arry: complay_arry, site_arry: site_arry, equipment_arry: equipment_arry, id: id },//查询的参数
  4. url: "/Role/DataRole",//提交的路径
  5. success: function (res2) {
  6. alert(res2.message);
  7. location.href = "/Role/Edit/"+id;
  8. }
  9. })

成功之后跳转界面

mvc返回json数据的更多相关文章

  1. Spring MVC返回json数据给Android端

    原先做Android项目时,服务端接口一直是别人写的,自己拿来调用一下,但下个项目,接口也要自己搞定了,我想用Spring MVC框架来提供接口,这两天便抽空浅学了一下该框架以及该框架如何返回json ...

  2. spring mvc 返回json数据的四种方式

    一.返回ModelAndView,其中包含map集 /* * 返回ModelAndView类型的结果 * 检查用户名的合法性,如果用户已经存在,返回false,否则返回true(返回json数据,格式 ...

  3. Spring MVC 返回json数据 报406错误 问题解决方案

    将jackson jar包改为jackson-databind-2.5.0.jar  jackson-core-2.5.0.jar  jackson-annotations-2.5.0.jar(这个版 ...

  4. MVC 返回json数据

    使用 return Json(pageList, JsonRequestBehavior.AllowGet); 返回object 使用 return Content(JsonConvert.Seria ...

  5. spring mvc 返回JSON数据

    servlet相关XML配置 <!--这个不启用会报错--><mvc:annotation-driven /> <bean class="org.springf ...

  6. Spring MVC返回JSON数据

    将一个对象以json数据格式返回前台: @ResponseBody public  User login(User user) { return user; } 在控制器上使用@ResponseBod ...

  7. spring mvc返回json字符串数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable

    1.spring mvc返回json数据,只需要返回一个java bean对象就行,只要这个java bean 对象实现了序列化serializeable 2. @RequestMapping(val ...

  8. 2.《Spring学习笔记-MVC》系列文章,讲解返回json数据的文章共有3篇,分别为:

    转自:https://www.cnblogs.com/ssslinppp/p/4528892.html 个人认为,使用@ResponseBody方式来实现json数据的返回比较方便,推荐使用. 摘要 ...

  9. 【Spring学习笔记-MVC-4】SpringMVC返回Json数据-方式2

    <Spring学习笔记-MVC>系列文章,讲解返回json数据的文章共有3篇,分别为: [Spring学习笔记-MVC-3]SpringMVC返回Json数据-方式1:http://www ...

随机推荐

  1. python 环境配置的导入与导出

    Python——配置环境的导出与导入   导出Python环境安装包[root@bogon ~]# pip freeze > packages.txt这将会创建一个 packages.txt文件 ...

  2. 使用 Docker Alpine 镜像安装 nginx

    微镜像Alpine,Alpine Linux 是一款独立的⾮商业性的通⽤ Linux 发行版,Alpine Linux 围绕 musl libc 和 busybox 构建,尽管体积很小,Apline ...

  3. Python语言基础04-构造程序逻辑

    本文收录在Python从入门到精通系列文章系列 学完前面的几个章节后,博主觉得有必要在这里带大家做一些练习来巩固之前所学的知识,虽然迄今为止我们学习的内容只是Python的冰山一角,但是这些内容已经足 ...

  4. Docker介绍及安装(一)

    一.Docker简介 1.1 docker介绍 Docker 使用 Google 公司推出的 Go 语言 进行开发实现,基于 Linux 内核的cgroup,namespace,以及 AUFS 类的 ...

  5. python爬虫(5)——BeautifulSoup & docker基础

    BeautifulSoup基础实战 安装:pip install beautifulsoup4 常用指令: from bs4 import BeautifulSoup as bs import url ...

  6. Bayesian Optimization使用Hyperopt进行参数调优

    超参数优化 Bayesian Optimization使用Hyperopt进行参数调优 1. 前言 本文将介绍一种快速有效的方法用于实现机器学习模型的调参.有两种常用的调参方法:网格搜索和随机搜索.每 ...

  7. LeetCode 112. Path Sum路径总和 (C++)

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  8. VIJOS-P1625 精卫填海

    JDOJ 1587 VIJOS-P1625 精卫填海 https://neooj.com/oldoj/problem.php?id=1587 洛谷 P1510 精卫填海 https://www.luo ...

  9. pytest--fixture

    前戏 fixture是在测试函数运行前后,由pytest执行的外壳函数.fixture中的代码可以定制,满足多变的测试需求,包括定义传入测试中的数据集.配置测试前系统的初始状态.为批量测试提供数据源等 ...

  10. 从Java官网下载最新的文档(包含API文档)

    Java学习资料(适合c转java的同学): Java中带包(创建及引用)的类的编译 - 小明快点跑 JAVA 对象引用,以及对象赋值 - 飘来荡去. Java官网下载页:https://www.or ...