ASP.NET MVC删除数据
来源:互联网 发布:宝利通mcu服务器软件 编辑:程序博客网 时间:2024/05/18 03:47
Index.cshtml
@model IEnumerable<MvcExample.Models.Category><script type="text/javascript"> function Delete(categoryID) { if (confirm("确定要删除?")) { url = "/Category/Delete"; parameter = { id: categoryID }; $.post(url, parameter, function (data) { alert("删除成功!"); window.location = "/Category"; }); } }</script><table> <tr class="title"> <td> 名称 </td> <td> 操作 </td> </tr> @foreach (var item in Model) { <tr> <td> @item.CategoryName </td> <td> <input type="button" onclick="Delete(@item.CategoryID)" text="删除"/> </td> </tr> }</table>
CategoryController.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Data.Entity;using MvcExample.Models;namespace MvcExample.Controllers{ public class CategoryController : Controller { private MvcExampleContext ctx = new MvcExampleContext(); public ActionResult Index() { return View(ctx.Categories.ToList()); } [HttpPost] public ActionResult Delete(int id) { Category category = ctx.Categories.Find(id); ctx.Categories.Remove(category); ctx.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { ctx.Dispose(); base.Dispose(disposing); } }}
阅读全文
0 0
- ASP.NET MVC删除数据
- 解析ASP.NET Mvc开发之删除修改数据
- asp.net MVc 数据验证
- ASP.NET MVC 数据验证
- Asp.net Mvc 数据验证
- ASP.Net MVC开发基础学习笔记(9):查看详情、编辑数据、删除数据
- [Asp.net mvc]Asp.net mvc 使用Json传递数据
- ASP.NET批量删除数据
- ASP.NET MVC删除弹出提示框
- ASP.NET MVC删除弹出提示框
- asp.net mvc批量删除的实现
- DynamicData for Asp.net Mvc留言本实例 中篇 新建.删除.数据验证
- ASP.NET MVC 2中的数据验证
- ASP.NET MVC 八 DropDownList数据绑定
- Asp.net mvc 导出数据至PDF
- asp.net mvc 显示列表数据
- asp.net mvc 显示列表数据
- asp.net mvc jquery 提交json数据
- linux关于terminal的一些操作
- C#中@的作用
- 创建和销毁对象
- Source Insight 4.0 文件类型、编码格式、tab转空格、tab键自动补全设置。。。(二)
- 二维数组中的查找
- ASP.NET MVC删除数据
- 基本tcp socket编程
- 4.内联分帧
- 在一个递增有序链表中插入新结点并保持链表递增顺序不变
- LeetCode 526 Beautiful Arrangement
- MVC框架-Mentawai(2)
- Android Studio
- 5.head常用标签
- 网络端口分类