我有一个使用EF(数据库优先)的MVC应用程序。在编辑时,我注意到所有字段都是从数据库中填充的,但只有一个值(recording_id)。我在控制器中设置了一个断点,可以看到所有返回的值,但recording_id显示为空。该值填充在数据库中。该字段在模型中,我使用的是正确的模型。任何建议都很好。
查看
@model IEnumerable<ScoreCard.Models.Car>
@{
ViewBag.Title = Car Submission";
}
<div class="jumbotron">
<h3>Car Submission</h3>
<hr class="style1" />
<div class='row'>
<button class="btn btn-danger btn-lg" onclick="location.href='@Url.Action("Create", "Submission")';return false;"><span class="glyphicon glyphicon-plus-sign"></span> Create Call Submission</button>
<button class="btn btn-primary btn-lg" onclick="location.href='@Url.Action("Index", "Home")';return false;"><span class="glyphicon glyphicon-home"></span> Home</button>
<br /><br />
<div class='col-sm-12'>
<table class="table">
<tr>
<th>
Car ID
</th>
<th>
Date
</th>
<th>
Recording ID
</th>
<th></th>
</tr>
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.car_id)
</td>
<td>
@String.Format("{0:d}", item.car_date)
</td>
<td>
@Html.DisplayFor(modelItem => item.recording_id)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.id }) |
@Html.ActionLink("Details", "Details", new { id = item.id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.id })
</td>
</tr>
}
}
else
{
<tr><td><h5><span class="glyphicon glyphicon-info-sign"></span> No Records Found</h5></td><td></td><td></td><td></td></tr>
}
</table>
</div>
</div>
控制器
public ActionResult Index()
{
return View(db.Cars.ToList());
}
型号
public partial class Car
{
public int id { get; set; }
public string car_id { get; set; }
public string recording_id { get; set; }
public System.DateTime car_date { get; set; }
}