PUT function demonstration and apiput function demonstration in Web APIs
Insus. NET has been learning and practicing Web APIs over the past few days. How to obtain, submit, or save data. You can review the Post model to Web Api to create or save Data http://www.cnblogs.com/insus/p/4343833.html and add JSON Data to an existing JSON file http://www.cnblogs.com/insus/p/4344547.html, this saves serialized json data to a file.
Now, you can obtain and submit and save the data. Of course, you can update the data. In this article, we will learn how to operate Web APIs to update data, especially to edit and update data in files.
To update data, you must first display the data on the webpage, edit the data, and then update the data. To obtain the Web API data and display it on the webpage, we have learned how to review it here:
ASP. net mvc Web Api practice http://www.cnblogs.com/insus/p/4334316.html
Html Web pages use jQuery to pass Parameters and get Web API data http://www.cnblogs.com/insus/p/4337409.html
Http://www.cnblogs.com/insus/p/4341026.html for transferring multiple parameters and getting Web API data
Post model to Web Api http://www.cnblogs.com/insus/p/4343538.html
Go to the Api controller and add a PUT method. logic processing is described. For more information, see.
Determine whether List <Order> has an existing record:
Var oo = orders. Where (d => d. OrderNumber = order. OrderNumber). FirstOrDefault (); if (oo! = Null ){//...}View Code
Now we create an html webpage to display data and update data. In the dynamically generated data table, we add more columns to dynamically generate an update button after each row. This allows you to update data.
OK. Now we can write the jQuery program. First, we can display the data. Before processing this part, because the previous series of retrieved data all come from Entity and are now from files, you need to make some modifications to Get:
The following figure shows the data obtained from the Web Api and dynamically displayed on the logo of span or text:
During the design, you should know which data is editable, and those are read-only data and use different html tags for processing:
If there is no problem at this time, the data should be properly displayed:
Next we can write the Update button event. here we need to note that this button is generated dynamically. When we handle its Click event, we must use the jQuery delegate, for more information about jQuery event processing, see jQuery dynamic production of the ammonium button how to achieve event processing http://www.cnblogs.com/insus/p/4315984.html
Real-time Demonstration: