Upload image included in MVC model

前端 未结 3 1305
遥遥无期
遥遥无期 2020-12-09 17:54

I have the following model:

public class Photo
{
    public int PhotoId { get; set; }
    public byte[] ImageData { get; set; }
    public DateTime DateUploa         


        
3条回答
  •  遥遥无期
    2020-12-09 18:33

    View:

    @using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
       ...
       
       ...
    }
    

    Controller:

    [HttpPost]
    public ActionResult Create(Photo photo, HttpPostedFileBase ImageFile)
    {
        byte[] buf = new byte[ImageFile.ContentLength];
        ImageFile.InputStream.Read(buf, 0, buf.Length);
        photo.ImageData = buf;
        ...
    }
    

提交回复
热议问题