I am using MVC5 on visual studio 2017. I have made an empty controller and have written my code, after that now i have passed a model object to my view. now i am trying to code my view side but i have these issues: (i have read the similar question and couldn't fix these)
1- Although i have written below code as first line in my view but i cannot use intellisense suggestion for my model class.(i found it from one of the similar questions)
@model IEnumerable<MyProject.Models.Myclass>
2- I am using c# common keywords such as "foreach" but when i write let's say "fore" in the view it does not suggest me anything. while in the controller it suggests all of them.
In Razor Views whenever you want to use C# common keywords you must prefix it with the @ sign
So using what you have after declaring your model, you can loop through the collection and for example create a table
@model IEnumerable<MyProject.Models.Myclass>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Field1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Field2)
</td>
</tr>
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.