2017-11-14 17 views
0

私はMVCには新しく、小さな連絡先アプリを構築しています。私はデータベースを作成し、インデックスページはDBのデータを表示します。私の問題は私の詳細ページです。タイトルは表示されますが、データは表示されません。ここで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

私は行方不明で答えを投稿しました – J32

+0

あなたはなぜ[HttpPost]属性を表示しようとしているのですか?あなたのモデル。代わりに[HttpGet]メソッドを使用する必要があります – xurca

答えて

0

私が欠けていたものを解決するために管理しました。私の@Html.ActionLinkとは関係ありませんでした。

関連する問題