You have two options to make grid in mvc:
1) Using foreach loop in view.
Add following model list at the top of the page.
@model List<modellist> like @model List<mvc_project.model.studentmodel>
<table>
<tr>
<th>
First Name
</th>
<th>
Last Name
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@item.FirstName
</td>
<td>
@item.LastName
</td>
</tr>
}
</table>
Note: But have to do custom paging, sorting in this type of grid. So I suggest you to user
WebGrid like follows.
2) WebGrid Example.
@{
var grid = new WebGrid(source: Model, canPage: true, canSort: false);
}
@grid.GetHtml(
htmlAttributes: new { id = "gridId" },
fillEmptyRows: false,
mode: WebGridPagerModes.All,
firstText: "<< First",
previousText: "< Prev",
nextText: "Next >",
lastText: "Last >>",
columns: new[] {
grid.Column("FirstName", "Name"),
grid.Column("LastName", "Last Name"),
grid.Column(columnName: "Edit", format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.id })),
grid.Column(columnName: "Delete", format: (item) => Html.ActionLink("Delete", "Delete", new { id = item.id }, new { onclick = "return confirm('Are you sure you want to delete this record?');" }))
}
)
WebGrid is the best way in mvc to make to show data in grid because you have no need to do custom paging, sorting.