【问题标题】:linq query results to datatable in Viewlinq 查询结果到视图中的数据表
【发布时间】:2015-09-15 06:41:17
【问题描述】:

有什么方法可以在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>

【问题讨论】:

  • 你的javascript代码在哪里?因为您的 javascript 代码中似乎有一个错误,而不是您这里的错误。
  • @StephenMuecke,看我的脚本。

标签: c# asp.net-mvc linq datatable


【解决方案1】:

您在 head 中指定了 9 个列标题并在 body 中插入了 10 个列值。我怀疑您忘记添加列标题。在 head 标签中再添加一个列标题并检查。

【讨论】:

    猜你喜欢
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多