我有一个问题,其中我的模型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' –