Image upload and preview in mvc 2

I am browsing mvc 2 converting an asp.net site. On my page I need to upload an image and show a preview image.

A screenshot of my asp.net page is below.

Screen shoot of my asp.net

I created the model as

public class Contest
    {
        public int contestid { get; set; }
        public string ContestName { get; set; }
        public string Description { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int UserId { get; set; }
        public bool IsActive { get; set; }
        public string contestimage { get; set; }
    }

in my controller

public ActionResult Createcontest()
{
   ContestModel contest = new ContestModel();
   return View(contest);
}
[HttpPost]
    public ActionResult Createcontest(ContestModel contest)
    {
///inserting data
      return View(contest);
    }

If I use an iframe in my view to load image.then, how can I bind the file name to contestimage (I save the consimage to the database). is there any other way to download the image.

+3
source share
2 answers

// in u controller, you can do this

public ActionResult Show( int id )
     {


        byte[] Filecontent1 = null;


        foreach (byte[] Filecontent in db.ExecuteStoreQuery<byte[]>
       ("select Filecontent from [barcodes] where Barcode_Id = @p0 ", id))
        {
            Filecontent1 = Filecontent;
        }

        var imageData =   Filecontent1;

        return File( imageData, "image/jpg" );
    }

// Put this into consideration // automatically intercepts the Actionresult show

<tr><img src='<%= Url.Action("Show", "contollername",new {id = Model.itemid }) %>' /></tr>

id is required from url: http: // localhost // page / 1

where 1 is itemid

+1
source

All Articles