You can easily upload and delete the single or multiple files in a single hit of server and no need to call server function in each and every upload or delete of files.
Here I am taking one scenario as an example. Suppose we have Product information in a table and we want to upload multiple files for a single product.
1) In this case we need two tables one is related to Product and other is related to Product Files. Let’s first create these two tables in database (sql script is given in project source code).
2) Open Microsoft Visual Studio
3) Create a new asp.net mvc empty application and choose razor view engine to implement this example.
4) Download the following packages and include in your application.
b) Bootstrap (optional)
5) Add ADO.Net Entity Data Model for selecting the database tables (Product and Product File) in Models folder. It will generate .edmx in your application. This is called Database First Approach in Entity Framework.
6) Now create a _Layout.cshtml (master page) in Views/Shared folder and add reference of these files.
7) Now create a ProductController in controller folder in order to render following views:
a) Index (To display the list of the products)
b) Create (To create a new product)
c) Edit (To edit and update the existing product info)
d) Details (To view to details of existing product)
e) Delete (To Delete the existing Product)
8) Add an Index action and a View (view available in project source code):
9) Add a Create action (GET & POST) and its View (view available in project source code):
10) Same way you can add Edit, Detail and Delete actions and its view.
11) There is two common functions (Save & Delete) for upload and delete of file is also available in Product controller.
If you run an application, the output should be something like below screenshot:
You can add, edit, view and delete the product and its files as well.
Edit Product screenshot is given below:
Thanks for reading this article. The missing action and view is available in project source. If you have any question and doubt you can freely ask me and do not forget to give your valuable comments.