2016-04-01 8 views
2

私はaspmvcに組み込まれているテーブルビューに基づいてオブジェクトのリストを取得しました。このように見えます。 enter image description hereAsp MVCテーブルオブジェクトを中心にするには?

問題は、すべての要素を中央に揃えることです。コードはかなり一般的です。文字通り私が信じる生成コードです。

<table class="table"> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.m_EmailAddress) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_FirstName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_LastName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CellNumber) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyAddress) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyState) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyZip) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyPhone) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyWebsite) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_WorkTravelRange) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyCostCode) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.m_CompanyAccountType) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_EmailAddress) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_FirstName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_LastName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CellNumber) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyAddress) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyState) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyZip) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyPhone) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyWebsite) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_WorkTravelRange) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyCostCode) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.m_CompanyAccountType) 
     </td> 
     @*<td> 
      @Html.ActionLink("Edit", "Edit", new { id=item.m_IdentityCode }) | 
      @Html.ActionLink("Details", "Details", new { id=item.m_IdentityCode }) | 
      @Html.ActionLink("Delete", "Delete", new { id=item.m_IdentityCode }) 
     </td>*@ 

私の本能は...無駄にするのではなく、

<table class = "table" align = "center"> 

に教えてください。

私は正しい方向に向いていますか?お願いしてありがとう。

編集:

私は<th text-align: center>を試みたが、それはまだ整列左に見えます。

enter image description here

+1

スタイルを参照しているサイトのCSSファイル内のコードを置くことができます 'th'とテキスト整列'と 'td'要素:center' –

+0

@StephenMueckeはありがとう、サー。 – Eidenai

+0

@StephenMuecke私は質問を更新し、まだ一列に並ぶように見えます。 – Eidenai

答えて

4

あなたはちょうどあなたがあなたのページのマークアップでこれを含めることができ

.table th, .table td { 
    text-align: center; 
} 

を使用して、テーブル全体にスタイルを適用することができます...だから前に<table>

<style type="text/css"> 
    .table th, .table td { 
     text-align: center; 
    } 
</style> 
<table class="table"> 

か、あなたのレイアウトやビューが

+0

今すぐ試してみてください:Pとても簡単です。 – Eidenai

+0

うん、私は明らかに遅れている。どこに置くべきですか? – Eidenai

+1

あなたのCSSページに入っている@Eidenaiは、あなたの視点の上部にあなたのCSSページを参照する必要があります。すべてのテーブルを同じように動作させたくない場合は、centerAlignTableのように自分のクラスにしてください。 – rogerdeuce

2

使用<th align="center">... </th>

source

+0

ありがとう、私は今それを試してみます。 – Eidenai

+0

Derpなので、どうして私はそれがうまくいかないと思ったのかわかりませんが、ありがとうございます:)タイマーが立ち上がったときに回答として選択します。 – Eidenai

関連する問題