The idea is to add the following to index :
@model BraveryBranded.ASP.Models.News
@{
ViewBag.Title = "Index";
}
@RenderPage("~/Areas/Admin/Views/News/New.cshtml")
<hr/>
@RenderPage("~/Areas/Admin/Views/News/List.cshtml")
This is generating an error talking about models . Here is the print:
ThisismyList:
@modelIEnumerable<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 my 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")
}
Controller News code:
public ActionResult Index()
{
return View();
}
public ActionResult List()
{
var list = UpdateList();
return View(list);
}
public ActionResult New()
{
return View();
}