Estou tentando renderizar duas views criadas com o scaffolding, uma é para o Create e outra é para o List.
A ideia é juntar na index o seguinte:
@model BraveryBranded.ASP.Models.News
@{
ViewBag.Title = "Index";
}
@RenderPage("~/Areas/Admin/Views/News/New.cshtml")
<hr/>
@RenderPage("~/Areas/Admin/Views/News/List.cshtml")
Esta gerando um erro falando sobre os models. Segue abaixo o print:
Esta é a minha List:
@model IEnumerable<BraveryBranded.ASP.Models.News>
@{
ViewBag.Title = "Lista";
}
<h2>@ViewBag.Title</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.IDNews)
</th>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.PostDate)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.IDNews)
</td>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.PostDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</table>
E esta é minha Create:
@model BraveryBranded.ASP.Models.News
@{
ViewBag.Title = "Adicionar";
}
<h2>@ViewBag.Title</h2>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>News</legend>
<div class="editor-label">
@Html.LabelFor(model => model.IDNews)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.IDNews)
@Html.ValidationMessageFor(model => model.IDNews)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PostDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PostDate)
@Html.ValidationMessageFor(model => model.PostDate)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Código do Controller News:
public ActionResult Index()
{
return View();
}
public ActionResult List()
{
var list = UpdateList();
return View(list);
}
public ActionResult New()
{
return View();
}