How to delete uploaded files in ASP. net mvc applications.
During the upload, the real file is stored in a certain directory of the application. In the database table, only the basic information is stored. When deleting a transaction, note that there is no transaction to operate. The implementation method of Insus. NET is to first delete the files in the physical path and then delete the database records.
Open the database and write a stored procedure for deleting records:
Add a Delete method to FileLibraryEntity. cs:
Create a controller:
First, obtain the record information from the database, and then combine the file path to determine whether it exists and delete it if it exists. The last step is to delete database records.
Create View:
#1 mark to create a table header.
#2 Mark and reference the jQuery js library.
#3 mark, get all records and present them on tbody1.
Below is #4 mark the detailed code:
Demo: