我对MVC很新,我正在构建一个小型联系人应用程序。我创建了数据库,索引页面显示了数据库的数据。我遇到的问题是我的详细信息页面。它会显示标题,但不会显示任何数据。
这是我的模特:
namespace BCM.Models
{
using System;
using System.Collections.Generic;
public partial class Contact
{
public int Id { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
public string CompanyName { get; set; }
public string Address { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string City { get; set; }
public string County { get; set; }
public string Country { get; set; }
public string PostCode { get; set; }
public string Telephone { get; set; }
public string Telephone1 { get; set; }
public string Telephone2 { get; set; }
public string Telephone3 { get; set; }
public string Telephone4 { get; set; }
public string Email { get; set; }
public string Email2 { get; set; }
public string Website { get; set; }
public string Notes { get; set; }
}
}
这是我的控制器:
public ActionResult Details()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Contact contact = db.Contacts.Find(id);
if (contact == null)
{
return HttpNotFound();
}
return View(contact);
}
以下是我的观点的一部分:
@model BCM.Models.Contact
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<div>
<h4>Contact</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.FirstName)
</dt>
<dd>
@Html.DisplayFor(model => model.FirstName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Surname)
</dt>
<dd>
@Html.DisplayFor(model => model.Surname)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CompanyName)
</dt>
<dd>
@Html.DisplayFor(model => model.CompanyName)
</dd>
这是我的详细信息页面显示的内容: enter image description here
提前致谢
答案 0 :(得分:0)
管理我想要的东西。这与我的@ Html.ActionLink没有通过Id
有关