接下来讲讲删除 部分...
在查询的View那边可以看到下方程序码
@Html.ActionLink("删除", "Delete", new { categoryID = md.CategoryID }, new { @class = "glyphicon glyphicon-trash"})
注解:如果要传参数过去Action 可以加上 new { categoryID = md.CategoryID }
进入类别删除Controller
public ActionResult Delete(string categoryID)
{
try
{
var result = new Category().Delete_Category(categoryID);
if (result)
{
TempData["ResultMessage"] = String.Format("类别[{0}]成功删除", categoryID);
return RedirectToAction("Index", "Category");
}
else
{ //如果没有资料则显示错误讯息并导回Index页面
TempData["ResultMessage"] = "资料有误,请重新操作";
return RedirectToAction("Index", "Category");
}
}
catch (Exception e)
{
ViewBag.ResultMessage = e.ToString();
return View();
}
}
类别 Model模板
public class Category
{
[Required]
[Display(Name = "类别编号")]
[StringLength(4, ErrorMessage = "{0}的长度至少必须为{2}的字元。", MinimumLength = 1)]
public string CategoryID { get; set; }
[Display(Name = "类别名称")]
[StringLength(20, ErrorMessage = "{0}的长度至少必须为{2}的字元。", MinimumLength = 1)]
public string CategoryName { get; set; }
public Category()
{
}
public bool Delete_Category(string categoryID)
{
var result = false;
using (var conn = new MySqlConnection(GlobalFunction.GlobalConnString))
{
conn.Open();
using (var command = conn.CreateCommand())
{
command.CommandText = "Delete From Category Where Category = @Category;
command.Parameters.AddWithValue("@Category", categoryID);
command.ExecuteNonQuery();
result = true;
return result;
}
}
}
}
注解:实务上通常为了资料完整性是不会下Delete语法这点特别注意
<<: Day 14 : 案例分享(4.3) 签核与费用模组 - 签核关卡及条件设定
昨天提到了 Web Component , 今天先初步了解一下什麽是 WebComponent 跟他...
前言 大部分介绍Reactive Programming都一定会提到Backpressure,可能放...
上一篇讲到 interface,今天这篇会来讲 type, 他们两个功能几乎很像,但还是有些不一样...
参赛初衷 今年的参赛题目是「不只懂语法:Vue.js 观念篇」。去年的这时候刚刚学 JavaScri...
今天要来讲的是 Hash,与前面的加密不同,以上是我了解後整理出 Hash 的特点。 Hash 是不...