我想从表中检索小时列db.instantservices
我无法做到。我正在使用EF code
并且在浏览器上我可以看到这个详细信息页面,但看不到中的信息viewbag
。提前谢谢你
Classes-:
public class InstantService
{
public int InstantServiceID { get; set; }
public string ServiceName { get; set; }
public string InstantUserName { get; set; }
public string Title { get; set; }``
public string Description { get; set; }
public int Hours { get; set; }
public int InstantID { get; set; }
public Instants CurrentInstant { get; set; }
public virtual ICollection<Review> Reviews { get; set; }
}
public class Review
{
public int ReviewID { get; set; }
public InstantService Service { get; set; }
public int InstantServiceID { get; set; }
public string MyReview{ get; set; }
}
但是当使用这段代码时,我没有得到任何价值。代码 -:
public ViewResult Details(int id)
{
Review review = db.ReviewDB.Find(id);
ViewBag.ServiceHours = db.InstantServiceDB.Select(model => model.Hours);
return View(review);
}
查看代码-:
@{
ViewBag.Title = "Details";
}
<fieldset>
<legend>Review</legend>
<div class="display-label">Service</div>
<div class="display-field">
@Html.DisplayFor(model => model.Service.Title)
</div>
<div class="display-label">MyReview</div>
<div class="display-field">
@Html.DisplayFor(model => model.MyReview)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id=Model.ReviewID }) |
@Html.ActionLink("Back to List", "Index")
</p>
<div>
Total Hours required were -:
<div>
@ViewBag.ServiceHours
</div>
</div>