zoukankan      html  css  js  c++  java
  • ASP.NET MVC删除数据

    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);
            }
        }
    }
  • 相关阅读:
    HUE配置HBase
    HUE配置HIVE
    HUE配置hadoop
    HUE的安装
    CM (Cloudera Manager) 的安装,便于CDH的离线部署
    MapReduce -- 最短路径
    Mapreduce -- PageRank
    CentOS 建立本地yum源服务器
    js移动设备手机跳转地址代码
    离线存储
  • 原文地址:https://www.cnblogs.com/libingql/p/3493226.html
Copyright © 2011-2022 走看看