標籤:
在視頻上傳這兒做了好長時間,想了很多辦法。因為想做的是當點擊表徵圖的時候就讓視頻自動開始上傳不需要點提交按鈕,而上傳控制項file需要點擊提交按鈕之後才能上傳。
<body> <div class="container"> <div class="panel "> <div class="header"> <p>上傳視頻</p> </div> <div class="panel-body"> <div class="row-fluid"> <div class="picture"> <img style="cursor: pointer;" alt="" id="shangchuan" src="../../images/上傳表徵圖.jpg" /> </div> <div class="picture2"> @* @using (Html.BeginForm("Index", "UpLoad", FormMethod.Post, new { enctype = "multipart/form-data" })) { *@<form name="form1" action="/Upload" method ="post"enctype = "multipart/form-data" ><input type="file" name="file" id="myfile" value="" onchange ="UploadFile();" /> @*<input type="submit" name="Submit" id="Submit" />*@ </form> @* }*@</div> </div> <div class="t">上傳視頻,即表示您已同意<a href="Declaration"><strong>校園視頻上傳服務條款</strong></a>,請勿上傳色情,反動等違法視頻</div> <hr /> </div> </div> </div></body>
效果(有待上傳。)
Controller 裡:
public class UpLoadController : Controller { //GET: /UpLoad/ public ActionResult Index() { return View(); } public ActionResult Declaration() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult Index(HttpPostedFileBase file, uploadModel model) { if (file.ContentLength > 0) { //獲得儲存路徑 string filePath = Path.Combine(HttpContext.Server.MapPath("~/Uploads"), Path.GetFileName(file.FileName)); file.SaveAs(filePath); model.vedio = filePath; model.Id = Guid.NewGuid(); //model.Id=Request["text"]; uploadDB.UploadModel.AddVedio(model); } return View(); } } 視頻的上傳完成了,上傳時候的進度條又是一個痛點。還要繼續攻克。
asp.net mvc中實現視頻自動上傳