내 컨트롤러에서 비디오에 대한 세부 정보를 채우고 실제로 업로드 할 수 있기를 원했기 때문에 Video 클래스는 실제 비디오가 필요하지 않습니다. 다른 웹 서비스로 전달됩니다. ASP MVC 파일 업로드 HttpPostedFileBase가 null입니다.
public class VideoUploadModel
{
public HttpPostedFileBase vid { get; set; }
public Video videoModel { get; set; }
}
//
// POST: /Video/Create
[HttpPost]
public ActionResult Create(VideoUploadModel VM)
{
if (ModelState.IsValid)
{
db.Videos.AddObject(VM.videoModel);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.UserId = new SelectList(db.DBUsers, "Id", "FName", VM.videoModel.UserId);
return View(VM);
}
내보기에서 나는 양식을 제출하면 VM의 videoModel 부분이 작성하지만 실제 파일을 VID됩니다
@model LifeHighlightsShoeLace.Controllers.VideoController.VideoUploadModel
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
@using (Html.BeginForm("Create", "Video", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Video</legend>
<div class="editor-label">
@Html.LabelFor(model => model.videoModel.KalturaID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.videoModel.KalturaID)
@Html.ValidationMessageFor(model => model.videoModel.KalturaID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.videoModel.Size)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.videoModel.Size)
@Html.ValidationMessageFor(model => model.videoModel.Size)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.videoModel.Date)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.videoModel.Date)
@Html.ValidationMessageFor(model => model.videoModel.Date)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.videoModel.UploadedBy)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.videoModel.UploadedBy)
@Html.ValidationMessageFor(model => model.videoModel.UploadedBy)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.videoModel.UserId, "User")
</div>
<div class="editor-field">
@Html.DropDownList("UserId", String.Empty)
@Html.ValidationMessageFor(model => model.videoModel.UserId)
</div>
<div class="editor-field">
<input name="model.vid" type="file" />
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}가 null의이 . 아이디어가 있으십니까?
감사합니다 (그리고 @BuildStarted). 이제 create IE를 클릭하면 "IE에서 웹 페이지를 표시 할 수 없습니다."라는 오류가 표시되고 chrome이 localhost에 대한 연결이 중단되었음을 알립니다. 파일을 포함시키지 않으면 문제없이 게시됩니다. –
4mb보다 큰 파일을 선택했습니다. –
예. 고마워요! –