I am working on a small blog using ASP.NET Core(MVC 6) EF Visual Studio. I have trouble finding how to save images to a database. I have read about IFormfile but I do not really understand how to go about it, I am stuck. I am new to this and would love to have a little help.
I want to save the image to the post I am creating(In the same form). I, therefore, want to save it to postID. Then I need to be able to display the image, how do I do that? I know there is a lot to ask, but I do not know where to turn. Feel free to send links if you have any good tips or ideas.
Thanks in advance!
You may find this useful if u need to save to database. This was a modification of https://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files and lots of input from k7Boys answer here MVC 6 HttpPostedFileBase?
Blog Modal Class should have Img field like;
Controller;
Took me a couple of hours to get here. Now working on viewing the images in a view, am sure this will not be complex. Enjoy
You can use IFormFile to save image posted from view. Below is the sample code.
In view simply bind it with IFormFile property like:
In your controller you just need to save file on server like:
Try this its working fine