1
I’m trying to render two views created with the scaffolding, one is for the Create and another is for the List.
The idea is to join in index the following:
@model BraveryBranded.ASP.Models.News
@{
ViewBag.Title = "Index";
}
@RenderPage("~/Areas/Admin/Views/News/New.cshtml")
<hr/>
@RenderPage("~/Areas/Admin/Views/News/List.cshtml")
This generating an error talking about the models. Below is the print:
This is my 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>
And this is mine 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")
}
Code of Controller News:
public ActionResult Index()
{
return View();
}
public ActionResult List()
{
var list = UpdateList();
return View(list);
}
public ActionResult New()
{
return View();
}
Luiz, if you access the independent pages (create e lis) they work? You could paste the action code of this new page you created?
– Andre Calil
@Andrecalil worse is that they are not working!
– Luiz Negrini
I think Create is in error because the error message speaks from the list. You can add the code of each action as well?
– Andre Calil
@Andrecalil I didn’t finish the actions, however, it was to appear empty, because really the lists are empty, it was to appear their html.
– Luiz Negrini