What is the Best way to store an image uploaded by the user and then show it in my website?
- Store it as binary in DB. then how should I show it with `img`?
I think I should write it to a directory somehow then pass it’s address as `src` attribute of `img`. - I can store it somewhere in web server, store the address of image in database. then I should simply specify the address in database in `src` attribute.
- Other ways?!
in my opinion the second way is more convenient.
and another question!
In both case How Can I upload this images in html form? the @Html doesent hav anything like @Html.FileFor(...) and how can I get data of <input type='file'/> in my Action?
I appreciate any suggestion.
Yeah in my opinion as well.
Pretty easy. As always in an ASP.NET MVC application you start by designing a view model:
then you could have a controller with 2 actions (one rendering the view and another handling the file upload):
and finally you will have a corresponding strongly typed view that will contgain the form to upload the file:
Also I would recommend you reading
Phil Haack's blog postthat illustrates file uploading in ASP.NET MVC works.