I was wondering is it possible to do a counter for the number of items in a model, i know using list it is possible, but id prefer to use IEnumerable for the project purpose. it would be even better if it could be done in javascript for constant update but im not experienced enough in MVC and Javascript.
-Controller-
public class ModelController : Controller
{
private JobData db = new JobData();
//
// GET: /Model/
public ActionResult Index()
{
var Model = db.Models.OrderByDescending(model => model.ModelType);
int count = Model.Count();
return View(Model.ToList());
}
-View-
@model IEnumerable<JobTracker.Models.Model>
@{
ViewBag.Title = "Camera Models";
}
<script type="text/javascript" src="~/Scripts/Table.js"></script>
<table id="tfhover" class="tftable" border="1">
<tr>
<th>
@Html.DisplayNameFor(model => model.ModelType)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ModelType)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ModelID }) |
@Html.ActionLink("Details", "Details", new { id=item.ModelID })
@* @Html.ActionLink("Delete", "Delete", new { id=item.ModelID })*@
</td>
</tr>
}
</table>
You can just use @Model.Count()
to display count anywhere – (credit goes to @MukeshModhvadiya from the comment section)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With