JQuery updates and deletes ASP. net mvc data, and jquerymvc
I used to learn ASP. NET MVC, learn and apply, operate on data display, add, edit, update, delete, and other functions.
Many methods are the same, and they are convenient, fast, and efficient.
Today, the Insus. NET writing exercise directly updates and deletes the data bound to the Table.
In the project, create an object, that is, to communicate with the database and perform operations on the data:
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 ();}Source Code
In the project controller:
Create a view and bind data:
@ Using Insus. NET. Models; @ model IEnumerable <ToolLocation> <! DOCTYPE html>
The jQuery code in step #4 above:
Run it to see the effect:
The above is the data update function. The following implementation is to delete the data in the Table.
@ Using Insus. NET. Models; @ model IEnumerable <ToolLocation> <! DOCTYPE html>
The jQuery Code marked with #4 above is the core function of deletion:
Run the program to see the effect of deletion:
The following content is updated on
After the deletion is successful, we do not need to re-direct it. We only need to delete this line of html to achieve: