여기에서 비디오에 대한 주석을 하나의보기에 추가해야합니다. 나는이 비디오에 대한 비디오 및 설명을 표시하는 것과 같은 기본보기 코드를 가지고 있습니다. 데이터를 추가 할 부분 뷰
<!-- language: C# -->
@model AzureMediaPortal.ViewModels.ViewModelWatch
@{
ViewBag.Title = "Watch";
}
<div id="videoPlayer">
</div>
<h2>@Html.DisplayFor(model => model.media.Title)</h2>
<h3> By @Html.DisplayFor(model => model.media.UserId) at @Html.DisplayFor(model => model.media.UploadDate) </h3>
@Html.HiddenFor(model => model.media.Id)
@Html.HiddenFor(model => model.media.AssetId)
@Html.HiddenFor(model => model.media.FileUrl, new { id = "fileUrl" })
<div class="display-label" style="font-weight:bold">
@Html.DisplayNameFor(model => model.media.Description)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.media.Description)
</div>
<br />
<div class="display-label" style="font-weight:bold">
@Html.DisplayName("Category")
</div>
<div class="display-field">
@Html.DisplayFor(model => model.media.Category.CategoryName)
</div>
<h3>Comments</h3>
@foreach (var item in Model.comment)
{
<div class="display-label" style="font-weight:bold">
@item.UserId
</div>
<div class="display-field">
@item.Content
</div>
}
@Html.Partial("Post",new AzureMediaPortal.ViewModels.ViewModelWatch())
@section Scripts {
<script src="~/Scripts/playerframework.min.js"></script>
<script src="~/Scripts/media-player.js"></script>
@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
mediaPlayer.initFunction("videoPlayer", $("#fileUrl").val());
</script>
}
본 부분 도면
@model AzureMediaPortal.ViewModels.ViewModelWatch
@{
ViewBag.Title = "Post";
}
<h2>Add Comment</h2>
@Html.HiddenFor(model => model.cmnt.MediaElement.Id)
@using (Html.BeginForm("Post","Home",FormMethod.Post)) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Add Comment</legend>
<div class="editor-label" style="font-weight:bold">
@Context.User.Identity.Name
</div>
<div class="editor-field">
@Html.TextAreaFor(model => model.cmnt.Content)
@Html.ValidationMessageFor(model => model.cmnt.Content)
</div>
<p>
<input type="submit" value="Post" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
이 내 뷰 모델
public class ViewModelWatch
{
public MediaElement media { get; set; }
public List<Comment> comment { get; set; }
public Comment cmnt { get; set; }
}
이며,이 난 부분 뷰로부터 데이터를 전달해야 내 컨트롤러
public ActionResult Watch(int id)
{
ViewModelWatch vm = new ViewModelWatch();
vm.media = _repository.GetMedia(id);
vm.comment = _repository.GetMediaComment(id);
return View(vm);
}
public ActionResult Post()
{
return View();
}
[HttpPost]
public ActionResult Post(Comment comment, int id)
{
if (ModelState.IsValid)
{
comment.UserId = User.Identity.Name;
comment.MediaElement.Id = id;
db.Comments.Add(comment);
db.SaveChanges();
return RedirectToAction("Watch");
}
return View();
}
인 그것을 데이터베이스에 저장하십시오. 미디어를 포함 시키십시오. 비디오에 삽입 된 주석을 알고 싶습니다.
감사합니다. muchhh
어디서 붙어 있습니까? – user13500
부분보기의 데이터를 데이터베이스에 삽입 할 수없고 부분보기에서 media.id를 가져 오는 방법 – veinvein