在表asp.net mvc中显示数据?

时间:2016-09-05 12:34:31

标签: c# asp.net asp.net-mvc bootstrap-table grid.mvc

我想将数据事件显示在表格中 在此之前,我能够在不使用桌子的情况下展示它们 但现在我想在一张桌子上展示 到目前为止,我能够做this

但我想放置" Faliure"在"名称"第一次发生和第二次恢复

这是我的控制器代码,我正在获取事件

 SqlDataReader reader_events = event_command.ExecuteReader();
                while (reader_events.Read())
                {
                    events.Add(Convert.ToString(reader_events["Event_Name"]));
                    events.Add(Convert.ToString(reader_events["Occurrence_Time"]));
                    events.Add(Convert.ToString(reader_events["Recovery_Time"]).Replace("\n", Environment.NewLine));
                    //events.Add(string.Concat(Convert.ToString(reader_events["Event_Name"]) + " - " +" Occur " + Convert.ToString(reader_events["Occurrence_Time"]) + " - " + " Recover " + Convert.ToString(reader_events["Recovery_Time"]).Replace("\n", Environment.NewLine)));

                    //events.Add(string.Concat(" Power Failure " + " Event ID # " + Convert.ToString(reader_events["Event_ID"]) + " Device ID # " + Convert.ToString(reader_events["Device_ID"]) + " Occur at " + Convert.ToString(reader_events["Occurrence_Time"]) + " Recover at " + Convert.ToString(reader_events["Recovery_Time"]).Replace("\n", Environment.NewLine)));
                    //events.Add(string.Concat(" Power Failure " + " Event ID # " + Convert.ToString(reader_events["Event_ID"]) + ", Device ID # " + Convert.ToString(reader_events["Device_ID"]) + ", Occured " + Convert.ToString(reader_events["Occurrence_Time"]) + ", Recover " + Convert.ToString(reader_events["Recovery_Time"]).ToList().ToPagedList(page ?? 1, 5)));
                }

我已将视图数据中的事件传递为

 ViewData["events"] = events;

在我的布局(视图)中我已经完成了这个

 <table class="table table-bordered table-responsive table-hover">
                  <tr>
                      <th>
                         Name
                      </th>
                      <th>
                          Occur
                      </th>
                      <th>
                          Recover
                      </th>
                  </tr>
                    <tbody>
                        @foreach (var item in ViewData["events"] as List<string>)
                        {
                            <tr>

                                <td style="border:1px solid black">
                                    @Html.DisplayTextFor()
                                    <fieldset>
                                        <b style="text-align:center; width:22%; font-family:'Agency FB'; font-size:small; background-color:#C8E6C9; color:red">

                                        </b>
                                    </fieldset>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>

我错过了什么? 任何帮助将不胜感激

更新

我在这里得到什么

error1

名称来自一个表,同时发生并从另一个表中恢复

1 个答案:

答案 0 :(得分:0)

<table class="table table-bordered table-responsive table-hover">
            <tr>
                <th>
                    Name
                </th>
                <th>
                    Occur
                </th>
                <th>
                    Recover
                </th>
            </tr>
            <tbody>@{
                if (ViewData["Data"] != null)
                {
                    if (ViewData.Values != null && ViewData.Values.Count() > 0)
                    {
                        foreach (var item in ViewData["Data"] as List<string>)
                        {
                            <tr>

                                <td style="border:1px solid black">
                                    @Html.DisplayTextFor(model => item.Name);

                                    <fieldset>
                                        <b style="text-align:center; width:22%; font-family:'Agency FB'; font-size:small; background-color:#C8E6C9; color:red">

                                        </b>
                                    </fieldset>
                                </td>
                                <td style="border:1px solid black">
                                    @Html.DisplayTextFor(model => item.Occur);
                                    <fieldset>
                                        <b style="text-align:center; width:22%; font-family:'Agency FB'; font-size:small; background-color:#C8E6C9; color:red">

                                        </b>
                                    </fieldset>
                                </td>
                                <td style="border:1px solid black">
                                    @Html.DisplayTextFor(model => item.Recover);
                                    <fieldset>
                                        <b style="text-align:center; width:22%; font-family:'Agency FB'; font-size:small; background-color:#C8E6C9; color:red">

                                        </b>
                                    </fieldset>
                                </td>
                            </tr>
                        }
                    }
                }
            }</tbody>

希望这会对你有所帮助。