我正在使用一個asp.net mvc web應用程式。我已經創建了一個表,現在我想在
但我得到了這個結果......所以我錯過了資料化插件的外觀,并出現了以下錯誤。
但是我得到了這個......所以我錯過了資料化插件的外觀和以下錯誤。
不能設定未定義的屬性(設定'_DT_CellIndex')
我的觀點:
@model List<Fright>/span>
@{
ViewData["Title"] = "Home Page";
var result = Model.GroupBy(gb => gb.Value);
}
<! DOCTYPE html>
<html>
<head>
<script src="https://code. jquery.com/jquery-3.5.1.js"></script>
<link href="/cdn.datatables. net/1.11.2/css/jquery.dataTables.min.css" rel="styleheet"/>
< script type="text/javascript" charset="utf8" src="/cdn. datatables.net/1.11.2/js/jquery.dataTables.min.js" defer></script>
<script>/span>
$(document).ready(function () {
$('#homeTable').DataTable()。
});
</script>>
</head>
<body>
<div>
< table id="homeTable" class="display"/span> style="width: 100%">
<thead>
<tr>/span>
<th>/span>Value</th>
<th>/span>Option</th>/span>
</tr>/span>
</thead>/span>
<tbody>/span>
@foreach (var item in result)
{
var url = "/frightSummary/SummaryIndex?id=" item.Key;
<tr>
<td>
<a href=@url>/span>@item。 Key</a>。
</td>。
</tr>
}
</tbody>
</table>/span>
</div>
</body>
</html>
uj5u.com熱心網友回復:
你的問題是<td> </td>的數量不匹配。你只是在foreach回圈中渲染了1個<td>,但你在表頭有兩個<th></th>
@model List<Fright>
@{
ViewData["Title"] = "Home Page";
var result = Model.GroupBy(gb => gb.Value);
}
<! DOCTYPE html>
<html>
<head>
<script src="https://code. jquery.com/jquery-3.5.1.js"></script>
<link href="/cdn.datatables. net/1.11.2/css/jquery.dataTables.min.css" rel="styleheet"/>
< script type="text/javascript" charset="utf8" src="/cdn. datatables.net/1.11.2/js/jquery.dataTables.min.js" defer></script>
<script>/span>
$(document).ready(function () {
$('#homeTable').DataTable()。
});
</script>>
</head>
<body>
<div>
< table id="homeTable" class="display"/span> style="width: 100%">
<thead>
<tr>/span>
<th>/span>Value</th>
<th>/span>Option</th>/span>
</tr>/span>
</thead>/span>
<tbody>/span>
@foreach (var item in result)
{
var url = "/frightSummary/SummaryIndex?id=" item.Key;
<tr>
<td>
<a href=@url>/span>@item。 Key</a>。
</td>。
<td>
<a href=@url>/span>@item。 選項</a> /*輸出你的選項值*/。
</td> </ td>
</tr>
}
</tbody>
</table>/span>
</div>
</body>
</html> ````
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/331779.html
標籤:
上一篇:.NET中的反思
