So I have a project which is a Shopping Cart, I have to save images to the database instead of uploading them to the server, here is my model. So Im unsure how to go about the controller to insert images or the view to display them, I have search for information about this but I cant really find anything, Im using entity framework code first.
There are two easy ways to do images -- one is to simply return the image itself in the controller:. For the data-store, you would simply use a byte array varbinary max or blob or any compatible type. The controller would look something like:. How to save an image to Database using MVC 4 asp. Doing so means that you need to go through ASP. NET and the database server just to serve a file which you could be serving directly from the web server.
It can also somewhat complicate the backup picture for your database and site. In your entity model, map the BLOB database column to a byte[] property. Assign the content of the uploaded file to that property of the entity object, and save changes in the ObjectContext. Save files in database with entity framework. Question I have an ASP. Grid ,. Column "id" , "Image Id" ,. Column "Name" , "Name" ,. Column "Data" , "Image" ,.
ToBase64String item. Grid img". Related Articles. Add Comments. Thank you for the feedback. The comment is now awaiting moderation. You will be notified via email when the author replies to your comment. Please select a comment to reply. You can add your comment about this article using the form below.
Make sure you provide a valid email address else you won't be notified when the author replies to your comment Please note that all comments are moderated and will be deleted if they are Not relavant to the article Spam Advertising campaigns or links to other sites Abusive content.
Please do not post code, scripts or snippets. Required Invalid Email Address. Security code:. Required Invalid security code.
I declare, I accept the site's Privacy Policy. Add Comment.
0コメント