tags:

views:

27

answers:

1

Hi,

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  A: 

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)
marcind
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?
luminousSpark
Never mind. I got it. ^^
luminousSpark