繁体   English   中英

图像上传和预览在mvc 2中

[英]image upload and preview in mvc 2

我通过转换asp.net网站来学习mvc 2.在我的页面上我必须上传图像并显示图像的预览。

我的asp.net页面的屏幕截图如下。

我的asp.net的屏幕截图

我已经创建了模型

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; }
    }

在我的控制器中

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

如果我在我的视图中使用iframe上传image.then如何将文件名绑定到contestimage。(我正在保存对数据库的contestimage)。 有没有其他方法上传图像。

//在控制器中你可以做到这一点

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" );
    }

//将其放入视图中进行diplaying //自动挂钩Actionresult节目

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

它来自url:http:// localhost // page / 1

其中1是itemid

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM