2017-06-13 55 views
1

在我的ASP.NET Aplication,我有这个DB型号:enter image description here添加视频在ASP.NET C#

我想添加一个视频,所以我有这个控制器动作:

public ActionResult AddVideo(HttpPostedFileBase file, int id) 
 
     { 
 

 
      if (file != null) 
 
      { 
 
       SoftIdeiaEntities1 db = new SoftIdeiaEntities1(); 
 
       string VideoName = System.IO.Path.GetFileName(file.FileName); 
 
       string physicalPath = Server.MapPath("~/Video/" + VideoName); 
 

 

 
       // save image in folder 
 
       file.SaveAs(physicalPath); 
 

 
       //save new record in database 
 
       Video record = new Video(); 
 
       record.VideoName = VideoName; 
 
       record.ContentID = id; 
 

 

 
       db.Video.Add(record); 
 
       db.SaveChanges(); 
 
      } 
 
      //Display records 
 
      return View(); 
 
     }

而我的观点是:

@model SoftIdeiaFinalProject.Models.DB.Video 
 

 
@{ 
 
    ViewBag.Title = "AddVideo"; 
 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
 
} 
 

 
<h2>AddVideo</h2> 
 

 
@using (Html.BeginForm()) 
 
{ 
 
    @Html.AntiForgeryToken() 
 
    
 
    <div class="form-horizontal"> 
 
     Video<br /> 
 
     <input type="file" name="file" id="file" style="width: 100%;" /> <br /> 
 
     <input type="submit" value="Upload" class="submit" /> 
 
    </div> 
 
} 
 

 
<div> 
 
    @Html.ActionLink("Back to List", "Details", Url.RequestContext.RouteData.Values) 
 
</div>

我不能将图像保存在数据库和文件夹中。我能做些什么来解决这个问题?

+0

你说“我无法保存图像”......为什么不呢?它是否给出了一个错误(如果是这样,是什么)它只是“什么都不做”,它会做什么,但不是你所期望的? –

+0

它不起作用,但不要给我任何错误@EricBurdo –

回答