JQuery對(duì)ASP.NET MVC數(shù)據(jù)進(jìn)行更新刪除
以前學(xué)習(xí)ASP.NET MVC時(shí),學(xué)習(xí)與應(yīng)用,操作過(guò)數(shù)據(jù)顯示,添加,編輯,更新和刪除等功能。
很多方法是相通的,看自己是怎樣來(lái)進(jìn)行方便,快捷,高效率。
今天Insus.NET寫的練習(xí),是直接對(duì)綁定在Table的數(shù)據(jù)進(jìn)行更新,刪除。
在項(xiàng)目中,創(chuàng)建一個(gè)實(shí)體,也就是說(shuō),對(duì)數(shù)據(jù)庫(kù)時(shí)行通信,對(duì)數(shù)據(jù)進(jìn)行操作:
public IEnumerable<ToolLocation> GetAllToolLocations()
{
sp.ConnectionString = DB.ConnectionString;
sp.Parameters = null;
sp.ProcedureName = "usp_ToolLocation_GetAll";
DataTable dt = sp.ExecuteDataSet().Tables[0];
return dt.ToList<ToolLocation>();
}
public void Update(ToolLocation tl)
{
List<Parameter> param = new List<Parameter>() {
new Parameter("@ToolLocation_nbr", SqlDbType.SmallInt, 2, tl.ToolLocation_nbr),
new Parameter("@LocationName",SqlDbType.NVarChar,-1,tl.LocationName),
new Parameter("@Description",SqlDbType.NVarChar,-1,tl.Description),
new Parameter("@IsActive",SqlDbType.Bit,1,tl.IsActive)
};
sp.ConnectionString = DB.ConnectionString;
sp.Parameters = param;
sp.ProcedureName = "usp_ToolLocation_Update";
sp.Execute();
}
public void Delete(ToolLocation tl)
{
List<Parameter> param = new List<Parameter>() {
new Parameter("@ToolLocation_nbr", SqlDbType.SmallInt, 2, tl.ToolLocation_nbr)
};
sp.ConnectionString = DB.ConnectionString;
sp.Parameters = param;
sp.ProcedureName = "usp_ToolLocation_Delete";
sp.Execute();
}
在項(xiàng)目的控制器中:
創(chuàng)建視圖,并綁定數(shù)據(jù):
@using Insus.NET.Models;
@model IEnumerable<ToolLocation>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Edit</title>
<link href="~/Content/css/table.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.2.1.js"></script>
</head>
<body>
<div>
<table>
<tr>
<td>ToolLocation_nbr</td>
<td>LocationName</td>
<td>Description</td>
<td>IsActive</td>
<td></td>
</tr>
@foreach (var tl in Model)
{
<tr>
<td>@tl.ToolLocation_nbr<input id="Hidden1" type="hidden" value="@tl.ToolLocation_nbr" /></td>
<td>@Html.TextBox("LocationName", tl.LocationName)</td>
<td>@Html.TextBox("Description", tl.Description) </td>
<td>@Html.CheckBox("IsActive", tl.IsActive)</td>
<td>
<input class="Update" type="button" title="Update" value="Update" />
</td>
</tr>
}
</table>
</div>
</body>
</html>
Source Code
上面步驟#4的jQuery代碼:
運(yùn)行一下,看看效果:
上面是對(duì)數(shù)據(jù)進(jìn)行更新的功能,下面的實(shí)現(xiàn),是對(duì)Table內(nèi)的數(shù)據(jù)刪除。
@using Insus.NET.Models;
@model IEnumerable<ToolLocation>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Delete</title>
<link href="~/Content/css/table.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.2.1.js"></script>
</head>
<body>
<div>
<table>
<tr>
<td>ToolLocation_nbr</td>
<td>LocationName</td>
<td>Description</td>
<td>IsActive</td>
<td></td>
</tr>
@foreach (var tl in Model)
{
<tr>
<td>@tl.ToolLocation_nbr<input id="Hidden1" type="hidden" value="@tl.ToolLocation_nbr" /></td>
<td>@tl.LocationName</td>
<td>@tl.Description</td>
<td>@Html.CheckBox("IsActive", tl.IsActive, new { disabled = "disabled" })</td>
<td>
<input class="Delete" type="button" title="Delete" value="Delete" />
</td>
</tr>
}
</table>
</div>
</body>
</html>
上面標(biāo)記#4的jQuery代碼,即是刪除的核心功能:
運(yùn)行程序,看看刪除的效果:
刪除成功之后,我們不必重導(dǎo)向,只需要?jiǎng)h除這行html即可,來(lái)達(dá)到:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼
- asp.net mvc4 mysql制作簡(jiǎn)單分頁(yè)組件(部分視圖)
- 利用ASP.NET MVC+EasyUI+SqlServer搭建企業(yè)開發(fā)框架
- 使用jQuery向asp.net Mvc傳遞復(fù)雜json數(shù)據(jù)-ModelBinder篇
- ASP.NET MVC DropDownList數(shù)據(jù)綁定及使用詳解
- ASP.NET中MVC從后臺(tái)控制器傳遞數(shù)據(jù)到前臺(tái)視圖的方式
- Asp.net mvc 數(shù)據(jù)調(diào)用示例代碼
- ASP.NET MVC 數(shù)據(jù)驗(yàn)證及相關(guān)內(nèi)容
- ASP.NET Mvc開發(fā)之刪除修改數(shù)據(jù)
- ASP.NET中MVC傳遞數(shù)據(jù)的幾種形式總結(jié)
- ASP.NET Mvc開發(fā)之查詢數(shù)據(jù)
- asp.net實(shí)現(xiàn)的MVC跨數(shù)據(jù)庫(kù)多表聯(lián)合動(dòng)態(tài)條件查詢功能示例
- ASP.NET MVC使用EPPlus,導(dǎo)出數(shù)據(jù)到Excel中
相關(guān)文章
jquery中dom操作和事件的實(shí)例學(xué)習(xí)-表單驗(yàn)證
這個(gè)demo的效果是實(shí)現(xiàn)用戶輸入時(shí)提供實(shí)時(shí)提醒,并不一定要等到元素失去焦點(diǎn)時(shí)才提醒2011-11-11
jquery實(shí)現(xiàn)ajax加載超時(shí)提示的方法
這篇文章主要介紹了jquery實(shí)現(xiàn)ajax加載超時(shí)提示的方法,涉及jQuery中l(wèi)oad方法的ajax加載超時(shí)設(shè)置與提示信息處理技巧,需要的朋友可以參考下2016-07-07
基于jquery的點(diǎn)擊鏈接插入鏈接內(nèi)容的代碼
基于jquery的點(diǎn)擊鏈接插入鏈接內(nèi)容的代碼,感覺有bug,解決的朋友可以留言方便更多的朋友2012-07-07
省市區(qū)三級(jí)聯(lián)動(dòng)jquery實(shí)現(xiàn)代碼
這篇文章主要為大家詳細(xì)紹了省市區(qū)三級(jí)聯(lián)動(dòng)jquery實(shí)現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10
jquery中g(shù)et,post和ajax方法的使用小結(jié)
本篇文章主要是對(duì)jquery中g(shù)et,post和ajax方法的使用進(jìn)行了詳細(xì)的介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02
webuploader模態(tài)框ueditor顯示問題解決方法
這篇文章主要為大家詳細(xì)介紹了webuploader模態(tài)框ueditor顯示問題的解決,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
簡(jiǎn)單的jQuery banner圖片輪播實(shí)例代碼
這篇文章主要介紹了簡(jiǎn)單的jQuery banner圖片輪播實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-03-03
jQuery maxlength文本字?jǐn)?shù)限制插件
相信大家對(duì)twitter類的微博客都不陌生,作為一句話博客其字?jǐn)?shù)即時(shí)提示效果設(shè)計(jì)的非常人性化.2010-04-04
jquery用ajax方式從后臺(tái)獲取json數(shù)據(jù)后如何將內(nèi)容填充到下拉列表
從后臺(tái)獲取json數(shù)據(jù),將內(nèi)容填充到下拉列表,頁(yè)面做如何處理,接下來(lái),通過(guò)本篇文章給大家實(shí)例講解jquery用ajax方式從后臺(tái)獲取json數(shù)據(jù)后如何將內(nèi)容填充到下拉列表,需要的朋友可以參考下2015-08-08









