日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

MVC3.0删除数据的时候给提示信息

發布時間:2025/3/21 c/c++ 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MVC3.0删除数据的时候给提示信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Index.cshtml代碼:

@model IEnumerable<FirstMvc.Models.Book><script type="text/javascript">function Delete(bkid) {if (confirm("確定刪除數據嗎?")) {//刪除的時候給提示url = "/Book/Delete";parameter = { id: bkid };$.post(url, parameter, function (data) {window.location = "/Book";});}}</script>@{ViewBag.Title = "首頁"; }<h2>圖書管理</h2><p>@Html.ActionLink("增加圖書", "Create") </p> <table><tr><th>圖書名稱</th><th>作者</th><th>出版社</th><th>價格</th><th>備注</th><th></th></tr>@foreach (var item in Model) {<tr><td>@Html.DisplayFor(modelItem => item.BookName)</td><td>@Html.DisplayFor(modelItem => item.Author)</td><td>@Html.DisplayFor(modelItem => item.Publisher)</td><td>@Html.DisplayFor(modelItem => item.Price)</td><td>@Html.DisplayFor(modelItem => item.Remark)</td><td><input type="button" value="刪除" οnclick="Delete(@item.BookID)" />
       @*第二種刪除方法*@
?????????? <a href="Book/Delete/@item.BookID" οnclick="return confirm('確定刪除數據?')">刪除</a></td><td>@Html.ActionLink("編輯", "Edit", new { id = item.BookID }) |@Html.ActionLink("查看", "Details", new { id = item.BookID }) |@Html.ActionLink("刪除", "Delete", new { id = item.BookID })</td></tr> }</table>

BookController代碼:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using FirstMvc.Models;namespace FirstMvc.Controllers {public class BookController : Controller{//// GET: /Book/BookDbContext db = new BookDbContext();public ActionResult Index(){return View(db.Books.ToList());}public ActionResult Create(Book book){if (ModelState.IsValid){db.Books.Add(book);db.SaveChanges();return RedirectToAction("Index");}else{RedirectToAction("Index");}return View();}
      //刪除數據
public ActionResult Delete(int id){Book book = db.Books.Find(id); db.Books.Remove(book); db.SaveChanges();return RedirectToAction("Index");}} }

Book.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations;namespace FirstMvc.Models {public class Book{public int BookID { get; set; }[Required(ErrorMessage = "必須輸入圖書名稱")]public string BookName { get; set; }[Required(ErrorMessage = "必須輸入作者名稱")]public string Author { get; set; }[Required(ErrorMessage = "必須輸入出版社")]public string Publisher { get; set; }public decimal Price { get; set; }public string Remark { get; set; }} }

BookDbContext.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity;namespace FirstMvc.Models {public class BookDbContext:DbContext{public DbSet<Book> Books { get; set; }} }

?

轉載于:https://www.cnblogs.com/LoveQin/p/4692621.html

總結

以上是生活随笔為你收集整理的MVC3.0删除数据的时候给提示信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。