我目前只拥有CREATE VIEW我的专辑类:如何为我的模型创建一个Html.EditorFor以节省时间?
@model MvcApplication1.Models.AlbumViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>AlbumViewModel</legend>
<p>
@Html.LabelFor(model => model.GenreId)
@Html.DropDownListFor(x => x.GenreId, new SelectList(Model.Genres, "GenreId", "name"))
</p>
<p>
@Html.LabelFor(model => model.ArtistId)
@Html.DropDownListFor(x => x.ArtistId, new SelectList(Model.Artists, "ArtistId", "Name"))
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
有人告诉我,它的约定使用EditorFor用于创建和编辑,以节省时间,在未来。
所以我认为最终会看起来像这样:
@model MvcApplication1.Models.AlbumViewModel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@Html.EditorForModel
<div>
@Html.ActionLink("Back to List", "Index")
</div>
这是正确的吗?我如何以及在哪里声明并在解决方案中写下这些内容?
编辑:
我在我的主帐户有这种/注册查看:
@model Models.RegisterViewModel
@{
ViewBag.Title = "Register";
}
<h2>Register</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>RegisterViewModel</legend>
@Html.EditorFor(model => model.RegisterModel)
@Html.EditorFor(model => model.Cities)
@Html.EditorFor(model => model.Countries)
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
在我EditorTemplate:
@model Fooer.WebUI.Models.RegisterModel
THIS IS A TEST.
然而,它并不渲染该虚拟文本。它呈现模型的默认控件。
这不符合预期。请参阅编辑。 –