Model1 db = new Model1();
public int add(Wsl.Model.Ram model)
{
db.Ram.Add(model);
return db.SaveChanges();
}
public List<Ram> select() {
List<Ram> n = db.Ram.ToList();
return n;
}
public int del(int id)
{
Ram r = db.Ram.Find(id);
db.Ram.Remove(r);
return db.SaveChanges();
}
public Ram ft(int id)
{
return db.Ram.Where(m => m.id == id).FirstOrDefault();
}
public int update(Ram model)
{
Ram r = db.Ram.Where(m=>m.id==model.id).FirstOrDefault();
r.id = model.id;
r.Name = model.Name;
r.pwd = model.pwd;
r.email = model.email;
r.ModifedDate = model.ModifedDate;
r.Description = model.Description;
r.CName = model.CName;
return db.SaveChanges();
}
<script>
$.ajax({
url: "http://localhost:2678/wsl/select",
type: "get",
success: function (data)
{
$(data).each(function (i,data) {
tr = '<tr>'
+ '<td>' + data.Name + '</td>'
+ '<td>' + data.email + '</td>'
+ '<td>' + data.pwd + '</td>'
+ '<td>' + data.CName + '</td>'
+ '<td><a href="/Index/Map?name=' + data.Description+'">' +data.Description +'</a></td>'
+ '<td>' + data.ModifedDate + '</td>'
+ '<td><input id="Button1" type="button" value="删除" onclick="del(' + data.id + ')"/><input id="Button1" type="button" value="修改" onclick="update(' + data.id + ')"/></td>'
+ '</tr>'
$("#tab").append(tr);
})
}
})
function del(id) {
if (confirm("确认删除吗?")) {
$.ajax({
url: "http://localhost:2678/wsl/del?id="+id,
//data: { id: id },
type: "post",
success: function (data) {
if (data>0) {
aler("删除成功");
location.href = "/Index/select"
}
}
})
}
}
function update(id) {
location.href = "/Index/update?id=" + id;
}
</script>
$(function(id){
$.ajax({
url:"http://localhost:2678/wsl/ft?id="+@ViewBag.id,
type:"get",
//data:{id:@ViewBag.id},
success:function(data){
$("#Name").val(data.Name),
$("#email").val(data.email),
$("#pwd").val(data.pwd),
$("#CName").val(data.CName),
$("#Description").val(data.Description),
$("#ModifedDate").val(data.ModifedDate)
}
})
})
public ActionResult update(int id)
{
ViewBag.id = id;
return View();
}