I have this cshtml
@model IEnumerable<TreinamentoCrud.Models.Cidade>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.nome)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.nome)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.id }) |
@Html.ActionLink("Details", "Details", new { id=item.id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.id })
</td>
</tr>
}
</table>
When I call the controller of this View, I get this error:
System.NullReferenceException: 'Object reference not set to an instance of an object. '
That is, my model needs to be instantiated. How do I make the page work?
EDIT1
My controller (GetCities) currently, but I will change to Netinho's suggestion
public class CidadeController : Controller
{
// GET: GetCidade
public ActionResult Index()
{
return View();
}
public ActionResult GetCidades()
{
return View();
}
}
}