国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

JQuery對ASP.NET MVC數據進行更新刪除

2019-11-20 09:30:11
字體:
來源:轉載
供稿:網友

以前學習ASP.NET MVC時,學習與應用,操作過數據顯示,添加,編輯,更新和刪除等功能。
很多方法是相通的,看自己是怎樣來進行方便,快捷,高效率。
今天Insus.NET寫的練習,是直接對綁定在Table的數據進行更新,刪除。
在項目中,創建一個實體,也就是說,對數據庫時行通信,對數據進行操作:

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();  }

在項目的控制器中:

創建視圖,并綁定數據:

@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代碼:

運行一下,看看效果:


上面是對數據進行更新的功能,下面的實現,是對Table內的數據刪除。

@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>

上面標記#4的jQuery代碼,即是刪除的核心功能:

運行程序,看看刪除的效果:

刪除成功之后,我們不必重導向,只需要刪除這行html即可,來達到:

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 丹东市| 怀柔区| 汉源县| 阳曲县| 阿荣旗| 乌鲁木齐县| 屯昌县| 内黄县| 霍邱县| 临江市| 汉寿县| 娄底市| 绍兴县| 棋牌| 乐平市| 合阳县| 那坡县| 城市| 红桥区| 德州市| 永和县| 旅游| 同心县| 巨鹿县| 囊谦县| 西昌市| 内黄县| 大荔县| 林口县| 嘉峪关市| 双桥区| 溧水县| 钦州市| 康乐县| 来安县| 芜湖县| 洮南市| 扎囊县| 景德镇市| 安新县| 潍坊市|