I am working on a social media application with a UseregistrationController that needs to upload a user profile image of each user in the application. I want to retain the File input on the same Create/Edit view as the other fields i.e Name, Display Name, Email Address, Phone Number, etc.
So basically I need a registration page where the user must enter several database fields, including an image file. i.e post File Upload and other form fields to one action in ASP.NET MVC.
I have completed my task successfully so I thought let’s share the idea with other developers also so that they can get help.
In this post, we will cover the following points
- File Upload input as Part of Form with Other Fields
- How to pass other form data field along with MVC File Upload?
- MVC 5 Uploading file with one additional parameter
- MVC File Upload with more than one property
In the below articles I have explained about Uploading both data and files in FormData using Ajax MVC. Now I think you are clear about uploading the image file with form data in ASP.Net MVC applications. if you want do this task using the ajax call then read below article.
Let’s understand with an example, I have created an MVC view that has Name, Display Name, Email Address, Phone Number input fields inside a form.
and that form control has one file upload control for uploading the user profile picture. and we have specified the standard form elements with a file upload “multipart/form-data“. So multipart type handle for all form elements on the page.
Action Method Code
In action using the FormCollection object I’m getting form data value inside the controller and In Request.Files we can read our files.Using the entity framework and I’m performing insert in a database table.
If you have any questions related to the post let me know, I will respond.
Please also share this article to Facebook, Twitter, Reddit, and other social media platform to help developers who face the same issue.
Please like our Facebook and follow us on Twitter for the latest update of technology or for any support.
MVC is a way in which we divide our database, logic, and visual part. The full form of MVC is Model-View-Controller, which means that we call the database the model, the logic part is known as the controller and the visual part is known as the view.
Talking about the technical language, it is such an architectural pattern, with the help of which project management, security, and productivity can be increased by dividing any project into 3 components.
We are not talking about anyone special programming language here because you can use it in any project, whether it is in PHP, ASP.NET, Nodejs, Python, you can use this method in all.