1.视图代码
<script>
function denglu() {
var name = document.getElementById("name").value;
var uid = document.getElementById("uid").value;
var pwd = document.getElementById("pwd").value;
var caluses = [name, uid, pwd]
jQuery.ajax({
url: "/My/ValidateUser", //提交地址
type: "POST", //提交方式
data: { "Value": caluses }, //提交数据
//成功方法
success: function (data) {
if (data == "AddGo") {
alert("添加成功");
//跳转
jQuery(function () {
window.location.href="/my/index";
})
} else {
alert("没成功");
}
},
//错误
Error: function (c, v, d) {
alert("错误");
}
})
}
</script>
2.控制器代码
public ActionResult ValidateUser(List<string> Value)
{
// TempData["aa"] = Value;
using (MVCTwoEntities1 db = new MVCTwoEntities1())
{
Usera u = new Usera();
u.uname = Value[0];
u.pwd = Value[1];
u.Uids = Value[2];
//添加
db.Usera.Add(u);
if (db.SaveChanges()>0)
{
return Content("AddGo");
}
else
{
return Content("Fash");
}
}
}