Mat*_*093 5 c# model-view-controller ienumerable model
我想知道是否有可能为模型中的项目数量做一个计数器,我知道使用list是可能的,但id更喜欢使用IEnumerable用于项目目的.如果它可以在javascript中进行持续更新,但我在MVC和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());
}
Run Code Online (Sandbox Code Playgroud)
-视图-
@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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24868 次 |
| 最近记录: |