c# - 在 ASP.NET C# 中添加视频

标签 c# mysql asp.net

在我的 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>

我无法在数据库和文件夹中保存图像。我该怎么做才能解决这个问题?

最佳答案

关于c# - 在 ASP.NET C# 中添加视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44519314/

相关文章:

mysql触发查询。这是对的吗?

c# - 如何在 Entity Framework 中使用流利的 api 为一对零指定外键属性..一个关系

c# - 从 app.config 获取 WCF 客户端端点 IP

c# - WebClient DownloadFile 路径中的非法字符

c# - 如何在 c#/xaml Windows 商店应用程序中将 RTF 文件注入(inject) RichTextBlock

mysql - MySQL中haversine查询添加bounds的效率

php - 从函数调用 PDO

c# - 文档数据库请求连续 token 在第一次迭代时未设置

asp.net - 有什么方法可以过滤 IIS 提供的页面中的某些内容吗?

.net - 使用 .NET 在内存中通信