我不明白为什么我的视图有运行时错误。
@if (Model.PicturePath != null)
{
<dt>
@Html.DisplayNameFor(model => model.PicturePath)
</dt>
<dd>
@Html.DisplayFor(model => model.PicturePath)
</dd>
}
已编辑
这是一个简单的 CRUD 视图。你认为我应该只创建一个 ViewModel 并以这种方式检查 null 吗?通常,我总是使用 ViewModel。
@model PTSPortal.Models.File
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>File</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.FileName)
</dt>
<dd>
@Html.DisplayFor(model => model.FileName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FileSize)
</dt>
<dd>
@Html.DisplayFor(model => model.FileSize)
</dd>
@if (Model.FilePath != null)
{
<dt>
@Html.DisplayNameFor(model => model.FilePath)
</dt>
<dd>
@Html.DisplayFor(model => model.FilePath)
</dd>
}
<dt>
@Html.DisplayNameFor(model => model.CreateDate)
</dt>
<dd>
@Html.DisplayFor(model => model.CreateDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FileType)
</dt>
<dd>
@Html.DisplayFor(model => model.FileType)
</dd>
<dt>
@Html.DisplayNameFor(model => model.UserId)
</dt>
<dd>
@Html.DisplayFor(model => model.UserId)
</dd>
<dt>
@Html.DisplayNameFor(model => model.IsPublic)
</dt>
<dd>
@Html.DisplayFor(model => model.IsPublic)
</dd>
<dt>
@Html.DisplayNameFor(model => model.FriendlyName)
</dt>
<dd>
@Html.DisplayFor(model => model.FriendlyName)
</dd>
@if (Model.PicturePath != null)
{
<dt>
@Html.DisplayNameFor(model => model.PicturePath)
</dt>
<dd>
@Html.DisplayFor(model => model.PicturePath)
</dd>
}
</dl>
</div>
<br /><br />
l.FileType />
</video><video id="video1" class="video-js vjs-default-skin" controls preload="auto"
width="640" height="264" poster="@Url.Content(Model.PicturePath)"
data-setup='{"example_option":true}'>
<source src="@Url.Content(Model.FilePath)"
type=@Mode
<p>
@Html.ActionLink("Edit", "Edit", new { id = Model.FileId }) |
@Html.ActionLink("Back to List", "Index")
</p>
控制器:
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
PTSPortal.Models.File file = db.Files.Find(id);
if (file == null)
{
return HttpNotFound();
}
return View(file);
}