//只要改model就好
@model List<ShelfSystem.Data.CassetteHistory> //只要改model就好
@{
@using System.Reflection;@using System.ComponentModel;
}
<div class="row">
<div class="panel panel-default">
<div class="panel-heading">
<div class="bootstrap-admin-box-title">
@Html.Label("Cassette Move History")
</div>
</div>
@*萬用table*@
<div class="bootstrap-admin-panel-content">
<table class="table table-striped table-bordered">
<thead>
<tr>
@{
Type type = Model.GetType().GenericTypeArguments[0];
PropertyInfo[] PropertyList = type.GetProperties();
foreach (PropertyInfo item in PropertyList)
{
var attrs = item.GetCustomAttributes(typeof(DisplayNameAttribute), true).Cast<DisplayNameAttribute>().SingleOrDefault();
if (item.Name != "ID"&& attrs!=null)
{
<th>@Html.DisplayName(attrs.DisplayName)</th>
}
}
}
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Count(); i++)
{
<tr>
@foreach (PropertyInfo item in PropertyList)
{
if (item.Name != "ID")
{
if (item != null)
{
object value = item.GetValue(Model[i], null);
if (value != null)
{
<th>@Html.DisplayName(value.ToString())</th>
}
else
{
<th>@Html.DisplayName("NULL")</th>
}
}
}
}
</tr>
}
</tbody>
</table>
</div>
</div>
</div>