[英]linq query results to datatable in View
有什么方法可以使用jquery中的數據表顯示linq查詢結果嗎?
例子:
在我的控制器中:
public ActionResult All_Refers()
{
var results = db.rms_referred_vw.ToList();
return PartialView(results);
}
在我看來:
@model IEnumerable<RMSystem.Models.rms_referred_vw>
<table id="example">
<thead>
<tr>
<th>Referral ID</th>
<th>Badge No</th>
<th>Full Name</th>
<th>Department</th>
<th>Email</th>
<th>Date Hired</th>
<th>Referred By</th>
<th>Date Referred</th>
<th>Is Active?</th>
</tr>
</thead>
<tbody>
@foreach(var rfp in Model){
<tr>
<td>
@Ajax.ActionLink(Convert.ToString(rfp.rf_id), "Edit_Ref", new { rf_id = rfp.rf_id },
new AjaxOptions
{
HttpMethod = "POST",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "target6",
}, new {@style="color:darkblue", title = "Edit Referred Person"})
</td>
<td>@Html.DisplayFor(model => rfp.rf_badgeno)</td>
<td>@Html.DisplayFor(model => rfp.Fullname)</td>
<td>@Html.DisplayFor(model => rfp.dept)</td>
<td>@Html.DisplayFor(model => rfp.user_email)</td>
<td>@Html.DisplayFor(model => rfp.user_datehired)</td>
<td>@Html.DisplayFor(model => rfp.referredby)</td>
<td>@Html.DisplayFor(model => rfp.rf_createddate)</td>
<td>
@if (rfp.rf_isactive == true) {
<text>Yes</text>
}else{
<text>No</text>
}
</td>
<td><input type="button" value="Send Email for Regularization"/></td>
</tr>
}
</tbody>
但是當我嘗試使用這個時,我收到一個錯誤消息
“0x800a138f - JavaScript 運行時錯誤:無法獲取未定義或空引用的屬性‘fnSetData’,”
這是什么意思?
知道如何使用 jquery 中的數據表格式查看查詢結果嗎?
非常感謝你的幫助。
這是我的腳本代碼:
<script>
$(function(){
$("#example").dataTable();
})
</script>
您在 head 中指定了 9 列標題並在正文中插入了 10 個列值。我懷疑您忘記添加列標題。在 head 標記中再添加一個列標題並檢查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.