add
前台
<input id="Button1" type="button" value="button" onclick="add()" />
<input id="save" onclick="saveadd()" type="button" value="批量保存" />
<div>
<table>
<tr>
<td><input type="checkbox" checked='checked'/></td>
<td>编号</td>
<td>学号</td>
<td>名称</td>
<td>年龄</td>
</tr>
<tbody id="tname">
</tbody>
</table>
</div>
<script>
$(function () {
show();
})
function show() {
debugger;
$.ajax({
url: "/show/add",
type: "get",
dataType: "json",
success: function ( data) {
console.log(data);
alert(data);
debugger;
var str = '';
for (var i = 0; i < data.length; i++) {
str += " <tr>";
str += "<td><input type=\"checkbox\" checked='checked'/></td>";
str += "<td>" + data[i].id + "</td>";
str += "<td>" + data[i].xuehao + "</td>";
str += "<td>" + data[i].name + "</td>";
str += "<td>" + data[i].age + "</td>";
str += "<td> <input id='del' type=\"button\" class=\"btn btn-primary\" onclick=\"del(" + data[i].id + ")\" value=\"删除\" /></td>";
str += "</tr>";
}
$("#tname").append(str);
}
})
}
//添加
function add()
{
//var ss = Date.now();
var ss = Date.now();
debugger
var str = "";
str += " <tr class='ss'>";
str += "<td><input type=\"checkbox\" checked='checked'/></td>";
str += "<td><input id=\"Text2\" type=\"text\" /></td>";
str += "<td><input id=\"Text3\" type=\"text\" /></td>";
str += "<td><input id=\"Text4\" type=\"text\" /></td>";
str += "<td><input id='del' type=\"button\" class=\"btn btn-primary\" value=\"删除\" /></td>";
str += "</tr>";
$("#tname").append(str);
}
function saveadd()
{
var arry = [];
$(".ss").each(function () {
if ($(this).children().eq(0).children().first().prop("checked") == true)
{
var ss = $(this).children().eq(1).children().first().val();
var sss = $(this).children().eq(2).children().first().val();
var ssss = $(this).children().eq(3).children().first().val();
arry.push(JSON.stringify({ xuehao: ss, name: sss, age: ssss }));
}
})
$.ajax({
url: "/show/ad",
type: "post",
traditional: true,
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
data: { arry: arry },
success: function (data) {
if (data > 0) {
alert("添加成s功!");
show();
}
}
})
}
</script>
后台
//显示
public ActionResult add()
{
var data = new BLL.stuBLL().show();
var data2 = JsonConvert.SerializeObject(data);
return Content(data2);
}
//添加
[HttpPost]
public ActionResult ad(string[] arry)
{
var str = "insert into student values";//添加数据库拼接
stuModel mm = new stuModel();//类
var data = arry.ToList();
var ass = "";
for (int i = 0; i < data.Count; i++)//循环
{
ass = data[i];
var person1 = JsonConvert.DeserializeAnonymousType(ass, mm);//把json转换为mm类
str += "( '" + person1.xuehao + "','" + person1.name + "', '" + person1.age + "') ,";
}
int chu = str.LastIndexOf(',');
var sss = str.Substring(0, chu - 1);
int cg = new BLL.stuBLL().add(sss);
return Content(cg.ToString());
}
add的更多相关文章
- AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...
- EntityFramework Core 1.1 Add、Attach、Update、Remove方法如何高效使用详解
前言 我比较喜欢安静,大概和我喜欢研究和琢磨技术原因相关吧,刚好到了元旦节,这几天可以好好学习下EF Core,同时在项目当中用到EF Core,借此机会给予比较深入的理解,这里我们只讲解和EF 6. ...
- ASP.NET Core: You must add a reference to assembly mscorlib, version=4.0.0.0
ASP.NET Core 引用外部程序包的时候,有时会出现下面的错误: The type 'Object' is defined in an assembly that is not referenc ...
- [转]NopCommerce How to add a menu item into the administration area from a plugin
本文转自:http://docs.nopcommerce.com/display/nc/How+to+code+my+own+shipping+rate+computation+method Go t ...
- [deviceone开发]-动态添加组件add方法的示例
一.简介 这个示例详细介绍ALayout的add方法的使用(原理也适用于Linearlayout),以及add上去的新ui和已有的ui如何数据交换,初学者推荐.二.效果图 三.相关下载 https:/ ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Add Strings 字符串相加
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. ...
- [LeetCode] Expression Add Operators 表达式增加操作符
Given a string that contains only digits 0-9 and a target value, return all possibilities to add ope ...
- [LeetCode] Add Digits 加数字
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. ...
- [LeetCode] Different Ways to Add Parentheses 添加括号的不同方式
Given a string of numbers and operators, return all possible results from computing all the differen ...
随机推荐
- 关于C++中ios::sync_with_stdio(false)
粘贴自:https://blog.csdn.net/weixin_44015865/article/details/84974373 在C++中的输入和输出有两种方式,一种是scanf和printf, ...
- Servlet使用注解配置URl提示404错误
刚接触servlet 3.0,使用注释描述servlet @WebServlet(name="FirstServlet", urlPatterns="/FirstServ ...
- Qt对象树
Qt提供了一种机制,能够自动.有效的组织和管理继承自QObject的Qt对象,这种机制就是对象树.子对象动态分配空间不需要释放.
- Visual Studio 2017/2019 企业版 Enterprise 激活码
VS2017 Enterprise: NJVYC-BMHX2-G77MM-4XJMR-6Q8QF VS2017 Professional: KBJFW-NXHK6-W4WJM-CRMQB-G3CDH ...
- echarts 角度渐变环形图心得
今天做了一个图,把自己的遇到的问题和体会记录一下,以防忘记 echarts地址 https://gallery.echartsjs.com/editor.html?c=xEPtLLmG4G 参考官网地 ...
- 悲观并发 乐观并发 Entity Framework Core中的并发处理
悲观并发策略 A用户发起一个请求 开启了事务 查询到了某一条数据 进行修改 在A提交事务之前 其他人都不能对这条数据进行修改 这种策略最常见的一个问题就是死锁 比如A修改X记录,B修改Y ...
- xshell 使用root 连接ubuntu server
下载一个虚拟机,安装Ubuntu server 下载一个xshell 第一步 :先使用账号登录 第二步:给root设置初始密码 sudo passwd root 第三步:切换root 账户,使用vi ...
- 【Code Tools】Java微基准测试工具JMH之中级篇
一.JMH中的基本概念 1)Mode Mode 表示 JMH 进行 Benchmark 时所使用的模式.通常是测量的维度不同,或是测量的方式不同.目前 JMH 共有四种模式: 1.Throughput ...
- 自学Python Day1
Day1: 强制转换,打印类型.Python2(row input)=Python3 input input(Python2)不接受强制转换,输入和输出是一致的.加双引号是字符串,不加 ...
- D - Mayor's posters(线段树+离散化)
题目: The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campai ...