简体   繁体   English

MVC详细信息页面未显示任何数据

[英]MVC Details page not showing any data

I am pretty new to MVC and I am building a small contacts app. 我对MVC还是很陌生,并且正在构建一个小型联系人应用程序。 I have created the database and the Index page displays the data for the DB fine. 我已经创建了数据库,并且“索引”页面显示数据库的数据。 The Issue I have is my details page. 我的问题是我的详细信息页面。 It will display the titles but wont show any data. 它会显示标题,但不会显示任何数据。

Here is my Model: 这是我的模特:

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; }
    }
}

Here is my controller: 这是我的控制器:

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);
    }

And here is a section of my View: 这是我的观点的一部分:

@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>

This is what my details page shows: enter image description here 这是我的详细信息页面显示的内容: 在此处输入图片描述

Thanks in advance 提前致谢

Managed to work out what I was missing. 设法弄清我所缺少的。 It was to do with my @Html.ActionLink not passing through the Id 这与我的@ Html.ActionLink没有通过ID有关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM