Reputation: 1825
My question is simple and might not be important to other coders, but it would really help a lot if some one can explain to me why I can't get the Intellisense
working When using DisplayNameFor
. It is working on DisplayFor
or other models, but not this one. While it is not helping me to get the correct properties, it is however telling me when there is no such name of a property.
Error is Does not contain any definition for "insert variable here"
Well that is reassuring, why not tell me what is available then?
@model IEnumerable<RMQGrainsBeta.Models.ExpenseIndexViewModel>
@{
ViewBag.Title = "ExpensesIndex";
}
<h2>ExpensesIndex</h2>
<table class="table table-bordered">
<tr>
<th>
@Html.DisplayNameFor(model => model.SONumber)
</th>
<th>
@Html.DisplayNameFor(model => model.DateProcessed)
</th>
<th>
@Html.DisplayNameFor(model => model.Stats)
</th>
<th>
@Html.DisplayNameFor(model => model.TotalExpense)
</th>
</tr>
Example if I type in model.
<- this will not give me any Intellisense.
But if I continue to type in it, model.To
<- it will tell me that there is no definition of "To" in the Model.
Upvotes: 1
Views: 857
Reputation: 14250
Your model
in (model => model.*)
is IEnumerable<ExpenseIndexViewModel>
which does not have properties SONumber
, DateProcessed
, etc. Those are properties of ExpenseIndexViewModel
.
You'll need to iterate over the collection
@foreach(var item in Model)
{
@Html.DisplayNameFor(m => item.SONumber)
}
Upvotes: 1