当前位置:网站首页>Addition, deletion, query and modification of data
Addition, deletion, query and modification of data
2022-04-23 06:24:00 【Wood acridine】
Data addition, deletion, query and modification
First instantiation entity model
Inquire about
LINQ Standard query statement
Declare a variable :var a =from Variable in data source . Specific table
select Variable Query the data of the whole table
return json(a, JsonRequestBehavior.AllowGet) Return the data
newly added
In the page, first give the new button a click event , Define a method to pop up the new modal form , Call this method
example :
Submit the page data to the controller Complete a new operation
First get the data in the form , You can get one by one , You can also serialize forms
serialize
So let's define a variable , adopt ID The selector finds what needs to be serialized from Forms . serializeArray();
example :var dataArr = $("#frm").serializeArray(); Serialize the form as An array
Submit
use post Method
$.post(“URL”, Data submitted ,function( Receive the data returned by backfilling ){
alert(); Pop up the return value
Close modal box :$(“ Of the modal box ID”).modal(“hide”);
Save update page :window.location.reload(dataArr);
});
Method of submitting new data
Define methods
example :public ActionResult InsertStudent(SYS_Student modStudent){}( Receive data through entity class methods )
Define a variable to store information about the success or failure of the new addition
string str= "";
add to : Instantiated entity model . Data sheet .Add();
example :myModel.SYS_Student.Add(modStudent);
Data saving operation : Instantiated entity model . SaveChanges();
example :myModel.SaveChanges() ;
Finally, return the information to
return json(str,JsonRequestBehavior . AllowGet);
modify
- Select the data to be modified . Pop up the modified mode box
$(“ Of the modal box ID”).modal(“show”);
- Display the data to be modified in the modal box
Define a method in the controller through ID Find out the data
get data
$.post(URL, Data transferred { attribute : Property value },function(){
Data binding
$(ID).val(); adopt ID Find and assign
example :$("#upStudentName").val(data[0].studentName);
})
- Modify the save function in the mode box ( Modify the function )
Define a method in the controller to receive the data transmitted from the page
example :public ActionResult UpdateStudent(SYS_Student modStudent)
Define a variable to store information about the success or failure of the modification
string str= "";
adopt Entry() Pass the modified data back . Status code
example :myModel.Entry(modStudent).State = System.Data.Entity.EntityState.Modified;
Data saving operation : Instantiated entity model . SaveChanges();
example :myModel.SaveChanges() ;
Finally, return the information to
return json(str,JsonRequestBehavior . AllowGet);
Define the saving method in the modify mode box in the page
So let's define a variable , adopt ID The selector finds what needs to be serialized from Forms
example :var arrData = $("#frmModify").serializeArray();
Submit data
use post Method
$.post(“URL”, Data submitted ,function( Receive the data returned by backfilling ){
alert(); Pop up the return value
Close modal box :$(“ Of the modal box ID”).modal(“hide”);
Save update page :window.location.reload();
});
Delete
Write a input label , The type is
Define a method on the page
A query box pops up asking whether to delete data
if (window.confirm(" Delete this data ")) {
Declare a variable to get the of the element value value
use post Method
$.post(“URL”, Data submitted ,function( Receive the data returned by backfilling ){
alert(); Pop up the return value
Save update page :window.location.reload();
});
Define a method in the controller
example :public ActionResult DeleteStudent(int studentID)
Define a variable to store information about the success or failure of deletion
string str= "";
according to ID First query out the data to be deleted
The first method :linq Standard query
example :
The second method :lamda The method of expression
example :
adopt Remove() Method to delete the data to be deleted
example :myModel.SYS_Student.Remove(student);
Data saving operation : Instantiated entity model . SaveChanges();
example :myModel.SaveChanges() ;
Finally, return the information to
return json(str,JsonRequestBehavior . AllowGet);
版权声明
本文为[Wood acridine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210616405391.html
边栏推荐
- Graphic numpy array matrix
- Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
- Explain of MySQL optimization
- Plane semi intersecting plate
- D. Optimal partition segment tree optimization DP
- MySQL best practices for creating tables
- Optional best practices
- Example of ticket selling with reentrant lock
- 检测技术与原理
- Complete example demonstration of creating table to page - joint table query
猜你喜欢
自動控制(韓敏版)
MySQL table constraints and table design
檢測技術與原理
Why does the subscript of the array start from 0 instead of 1?
A sharp tool to improve work efficiency
Complete example demonstration of creating table to page - joint table query
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
Pytoch -- data loading and processing
线性代数第一章-行列式
Implementation of displaying database pictures to browser tables based on thymeleaf
随机推荐
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
Viewer: introduce MySQL date function
Custom exception class
線性代數第二章-矩陣及其運算
SQL injection
Class loading and classloader understanding
线性代数第二章-矩阵及其运算
Use Matplotlib. In Jupiter notebook Pyplot server hangs up and crashes
Mysql database foundation
10.Advance Next Round
Usage scenario of copyonwritearraylist
Framework analysis 1 Introduction to system architecture
Consistent hash algorithm used for redis cache load balancing
Delete and truncate
深度学习基础——简单了解meta learning(来自李宏毅课程笔记)
对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
How to grow at work
电机与拖动(戚金清版)学习整理
去噪论文阅读——[CVPR2022]Blind2Unblind: Self-Supervised Image Denoising with Visible Blind Spots
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)