I'm using asp.net MVC and sql server. I have created a page that get some information from user like name,price,... and also one image, and the page repeat it for 30 times. It means every time that user submit the firm all of the information save to database and fields become clear and the user must submit the next information. Now I want that every time that user submit the form the page display the previous uploaded images beside the it. But I don't know how to display the uploaded image. and also I want to know how to display all of the previous images. Please help me and show me some code! Many Thanks.
-
2Nobody here is going to write it for you. Try odesk or elance if you want that. – BZink Oct 26 '12 at 15:53
-
you can check all uploaded images before that user submit form through ajax – testCoder Oct 26 '12 at 15:57
3 Answers
If you are storing the Image in SQL as an image data type I would use a custom http handler to display the images on the Page. I use something similar to
public class ImageHandler : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
using (DataContext data = new DataContext())
{
var image = data.Products.Where(p => p.ID.ToString() == imageid).Select(p => p.Image).Single();
context.Response.BinaryWrite((byte[])image.ToArray());
context.Response.End();
}
}
}
To display the image just set the Image url to
ImageHandler.ashx?ImID={Id of the database entry}

- 1,859
- 11
- 12
-
1This is interesting, but it doesn't look like it's in the vein of ASP.NET MVC. What do you do in the controller method? What does the routing look like? How do you manage security? – Robert Harvey Oct 26 '12 at 15:58
chead23's answer is for the image part perfect. if you want to do it out of a mvc controller, have a look at this question: Write binary data as a response in an ASP.NET MVC web control
the answer from Freyday completes cheads23's answer.
The way you have your form set up is very cumbersome and unpractical, I would suggest implementing something like Flickr's image uploading/editing functionality.
For example, have one inputbox that allows selecting multiple images using SHIFT
/CTRL
keys, and then upload those. On the next page, you will have all the images as thumbnails, and to set the name/price the user can either click edit and the two fields appear with a submit button and you submit the change asynchronously.
Alternatively you can have the two forms under each photo and have one submit button.
P.S. First you need to show us what you have attempted before we can help you.

- 5,998
- 4
- 36
- 59