1

I'm quite new to asp.net MVC. I'm following the NerdDinner tutorial and have created an Edit page to modify the dinner information. This time, I want to somehow have a photo uploaded and save to the database when I press the Save button.

So how can I do this?

If possible, can anyone point me to a good tutorial that shows me how to upload photos and store it into my sql database?

1 Answer 1

2

I'm not familiar with any tutorials, but here are the general steps you would need to take:

  1. Modify your database and add a byte array column to your table
  2. Update your ORM model (depending on which version of NerdDinner you are using it might be LINQ to SQL or Entity Framework)
  3. Modify your edit view to include a <input type="file"/> tag
  4. In your POST action method read the file bytes from the request and store them in the database (this post can get you started: http://www.hanselman.com/blog/ABackToBasicsCaseStudyImplementingHTTPFileUploadWithASPNETMVCIncludingTestsAndMocks.aspx)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that. I had a look on the link you gave me. I have an error though on this part.... HttpPostedFile hpf = Request.Files[file] as HttpPostedFile; Cannot convert type 'System.Web.HttpPostedFileBase' to 'System.Web.HttpPostedFile' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion How can I fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.