在MVC 2的图片上传和preVIEW [英] image upload and preview in mvc 2
问题描述
我正在通过转换asp.net website.in我的网页式学习MVC 2我要上传图片并显示图像的preVIEW。
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页面的屏幕拍如下。
screen shoot of my asp.net page is given below.
我已经创建了模型
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数据库)。
是否有其他方法来上传图片。
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). is there any other method to upload image.
推荐答案
//在控制器U可以做到这一点。
//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" );
}
//把这个视图diplaying
//自动挂钩的ActionResult节目
//put this in view for diplaying //automatically hooks the Actionresult show
<tr><img src='<%= Url.Action("Show", "contollername",new {id = Model.itemid }) %>' /></tr>
ID从URL需要:HTTP://本地主机//页/ 1
id it takes from url:http://localhost//page/1
其中1是itemid的
where 1 is the itemid
这篇关于在MVC 2的图片上传和preVIEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!