0

データベースにこのテーブルがあります:

ここに画像の説明を入力

ブラウザーに値 (ModuleIDおよび) を表として表示しようとしています。DateEnteredビューに値を渡すためにビューバッグを使用していますが、現在は 1 行しか取得していないため、これは適切な方法ではありません。私が今していることは、

public ActionResult Index()
        {
            var modules = (from entries in _db.Modules
                           orderby entries.DateEntered
                           select entries);
            ViewBag.entries = modules.ToList();
            return View();
        }

上の図のテーブルからすべての行を取得してビューに渡すにはどうすればよいですか? 私の見解では、私は現在持っています:

@using BootstrapSupport

    @model Sorama.DataModel.SIS.ModuleStock.Module

    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/shared/_BootstrapLayout.basic.cshtml";
    }

    <table class="table table-striped">
        <caption></caption>
        <thead>
            <tr>
                <th>
                   Module ID
                </th>

                <th>
                    Date Entered
                </th>
            </tr>
        </thead>
        <tr>
             @foreach (var entry in ViewBag.entries)
            {
                <td>@entry.ModuleId</td>
                 <td>@entry.DateEntered</td>
            }
             <td>
                    <div class="btn-group">
                        <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                            Action
                            <span class="caret"></span>
                        </a>
                        <ul class="dropdown-menu">
                                <li>@Html.ActionLink("Details", "Details")</li>
                                @if (Request.IsAuthenticated && HttpContext.Current.User.IsInRole("Admin"))
                                {
                                    <li class="divider"></li>
                                    <li>@Html.ActionLink("Edit", "Edit")</li>
                                    <li>@Html.ActionLink("Delete", "Delete")</li>
                                }



                        </ul>
                    </div>

                </td>
        </tr>

    </table>

ModuleIDこれは、 ( and )だけでなく、行全体の値を示しています。DateEnteredこれはブラウザで取得したものですブラウザ出力

要約すると、テーブルからすべての行を取得したいが、特定の列のみを取得したい。これは現在の状況では起こっていません。提案?

4

2 に答える 2

1

これを試して

 public ActionResult Index()
    {
        ABCList abc=new ABCList();
        var modules = (from entries in _db.Modules
                       orderby entries.DateEntered
                       select new ABC {
                           id=entries.id,
                           ModuleTypeId=entries.ModuleTypeId,
                           ModuleId=entries.ModuleId,
                           DataEntered=entries.DataEntered
                        });
        abc.settings = modules.ToList();
        return View();
    }

  public class ABC
  {

    public long Id{ get; set; }
    public long ModuleTypeId{ get; set; }
    public string ModuleId{get;set;}
    public DateTime DataEntered{ get; set; }
  }

  public class ABCList{
    public List<ABC> Settings { get; set; }
  }

意見

  @model ABCList
  @foreach (var entry in Model.Settings)
 {
 <tr>
    <td>@entry.ModuleId</td>
    <td>@entry.DateEntered</td>
    <td>
        <div class="btn-group">
            <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                Action<span class="caret"></span>
            </a>
            <ul class="dropdown-menu">
                <li>@Html.ActionLink("Details", "Details")</li>
                @if (Request.IsAuthenticated && HttpContext.Current.User.IsInRole("Admin"))
                {
                    <li class="divider"></li>
                    <li>@Html.ActionLink("Edit", "Edit")</li>
                    <li>@Html.ActionLink("Delete", "Delete")</li>
                }       

            </ul>
        </div>    
    </td>
 </tr>
}
于 2013-06-20T10:16:34.503 に答える