我有一個問題,其中我的模型MP
的CompanyName
類屬性將不會顯示在我的ASP.NET MVC 5項目的Ratings
詳細信息頁面中。模型屬性不在詳細信息頁面中顯示ASP.NET MVC 5
我對這個視圖使用了兩種模型。 MP
類是Ratings
類的外鍵。
型號:Ratings
public class Ratings
{
//Rating Id (PK)
public int Id { get; set; }
[DisplayName("User Name")]
public string UserId { get; set; }
//Medical Practice (FK)
public int MpId { get; set; }
public MP MP { get; set; }
//User ratings (non-key values)
[DisplayName("Wait Time")]
[Required] //Adding Validation Rule
public int WaitTime { get; set; }
[Required] //Adding Validation Rule
public int Attentive { get; set; }
[Required] //Adding Validation Rule
public int Outcome { get; set; }
}
控制器:RatingsController
// GET: Ratings/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Ratings ratings = db.Ratings.Find(id);
if (ratings == null)
{
return HttpNotFound();
}
MP CompanyName = db.MedicalPractice.Find(id);
return View(ratings);
}
評分查看:詳細
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.MP.CompanyName)
</dt>
<dd>
@Html.DisplayFor(model => model.MP.CompanyName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.UserId)
</dt>
<dd>
@Html.DisplayFor(model => model.UserId)
</dd>
<dt>
@Html.DisplayNameFor(model => model.WaitTime)
</dt>
<dd>
@Html.DisplayFor(model => model.WaitTime)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Attentive)
</dt>
<dd>
@Html.DisplayFor(model => model.Attentive)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Outcome)
</dt>
<dd>
@Html.DisplayFor(model => model.Outcome)
</dd>
</dl>
你似乎並沒有被設置rating.MP'的'的價值,更不用說'rating.MP.CompanyName' –