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>
我不能將圖像保存在數據庫和文件夾中。我能做些什麼來解決這個問題?
你說「我無法保存圖像」......爲什麼不呢?它是否給出了一個錯誤(如果是這樣,是什麼)它只是「什麼都不做」,它會做什麼,但不是你所期望的? –
它不起作用,但不要給我任何錯誤@EricBurdo –