Я занимаюсь разработкой проекта по электронному обучению, и мне нужно загрузить видео. Я использую asp.net MVC в качестве внешнего интерфейса и sql server 2017 в качестве внутреннего бэкэнда.
Как я могу загрузить видео и сохранить его путь в моей базе данных, чтобы я мог извлечь его позже для отображения видео
Я пробовал этот код, но путь не сохраняется в моей базе данных, и нет ошибки
Вот моя модель
public class Video
{
public int VideoID { get; set; }
public int CourseID { get; set; }
[Required]
[StringLength(100, ErrorMessage = "Please enter the title for the Video")]
public string Title { get; set; }
public string Path { get; set; }
public int CourseName { get; set; }
public virtual ECourse Course { get; set; }
}
cotroller
public ActionResult Create()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "VideoID,CourseID,Title,Path,CourseName")] Video video)
{
if (ModelState.IsValid)
{
db.Videos.Add(video);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(video);
}
View
@model eLearning.Models.Video
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Video</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.CourseID, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CourseID, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CourseID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Path, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="Path" />
@Html.ValidationMessageFor(model => model.Path, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CourseName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CourseName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CourseName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>