[英]image upload and preview in mvc 2
我通過轉換asp.net網站來學習mvc 2.在我的頁面上我必須上傳圖像並顯示圖像的預覽。
我的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)。 有沒有其他方法上傳圖像。
您只需使用<img src= ...>
來預覽圖像
這是一個例子: - http://weblogs.asp.net/imranbaloch/archive/2010/04/03/image-preview-in-asp-net-mvc.aspx
將圖像上傳到數據庫並進行預覽: http : //byatool.com/mvc/asp-net-mvc-upload-image-to-database-and-show-image-dynamically-using-a-view/
//在控制器中你可以做到這一點
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.