[英]image upload and preview in mvc 2
i am learing mvc 2 by converting a asp.net website.in my page i have to upload a image and show the preview of image. 我通过转换asp.net网站来学习mvc 2.在我的页面上我必须上传图像并显示图像的预览。
screen shoot of my asp.net page is given below. 我的asp.net页面的屏幕截图如下。
i have 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 am using iframe in my view to upload image.then how can i bind the file name to contestimage.(i am saving contestimage to database). 如果我在我的视图中使用iframe上传image.then如何将文件名绑定到contestimage。(我正在保存对数据库的contestimage)。 is there any other method to upload image. 有没有其他方法上传图像。
You can simply use <img src= ...>
to preview image 您只需使用<img src= ...>
来预览图像
Here is an example :- http://weblogs.asp.net/imranbaloch/archive/2010/04/03/image-preview-in-asp-net-mvc.aspx 这是一个例子: - http://weblogs.asp.net/imranbaloch/archive/2010/04/03/image-preview-in-asp-net-mvc.aspx
Upload image to database and preview it: http://byatool.com/mvc/asp-net-mvc-upload-image-to-database-and-show-image-dynamically-using-a-view/ 将图像上传到数据库并进行预览: http : //byatool.com/mvc/asp-net-mvc-upload-image-to-database-and-show-image-dynamically-using-a-view/
//in controller u 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 in view for diplaying //automatically hooks the Actionresult show //将其放入视图中进行diplaying //自动挂钩Actionresult节目
<tr><img src='<%= Url.Action("Show", "contollername",new {id = Model.itemid }) %>' /></tr>
id it takes from url:http://localhost//page/1 它来自url:http:// localhost // page / 1
where 1 is the itemid 其中1是itemid
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.