在我的 ASP.NET 应用程序中,我有这个数据库模型:enter image description here
我想添加一个视频,所以我有这个 Controller Action :
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>
我无法在数据库和文件夹中保存图像。我该怎么做才能解决这个问题?
最佳答案
也许你可以从网上导入图片?
https://forums.asp.net/t/2104234.aspx?Convert+HTML+string+URL+to+Image+using+asp+net+C+
关于c# - 在 ASP.NET C# 中添加视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519314/