LINQ查询结果以数据表视图 [英] linq query results to datatable in View

查看:75
本文介绍了LINQ查询结果以数据表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法如何使用数据表jQuery中显示LINQ查询结果?

例如:

在我的控制器:

 公众的ActionResult All_Refers()
    {
        变种结果= db.rms_referred_vw.ToList();
        返回PartialView(结果);
    }

在我看来:

  @model IEnumerable的< RMSystem.Models.rms_referred_vw><表ID =榜样>
<&THEAD GT;
    &所述; TR>
        <第i推荐ID< /第i
        <第i个徽章否LT; /第i
        <第i全名< /第i
        <第i个部门和LT; /第i
        <第i个电子邮件和LT; /第i
        <第i日期聘请< /第i
        <第i提到所谓LT; /第i
        <第i日期简称< /第i
        百分位中的一个是主动<?/第i个
    < / TR>
< / THEAD>
<&TBODY GT;@foreach(以型号VAR RFP){
    &所述; TR>
        &所述; TD>
             @ Ajax.ActionLink(Convert.ToString(rfp.rf_id),Edit_Ref,新的{RF_ID = rfp.rf_id},
                    新AjaxOptions
                    {
                      列举HTTPMethod =POST
                      InsertionMode = InsertionMode.Replace,
                      UpdateTargetId =target6
                    },{新款式@ =COLOR:darkblue,标题=编辑简称人})
        < / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.rf_badgeno)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.Fullname)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.dept)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.user_email)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.user_datehired)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.referredby)LT; / TD>
        < TD> @ Html.DisplayFor(型号=> rfp.rf_createddate)LT; / TD>
        &所述; TD>
            @if(rfp.rf_isactive ==真){
                <文字和GT;是< /文字和GT;
            }其他{
               <文字和GT否LT; /文字和GT;
            }
        < / TD>
         < TD><输入类型=按钮值=发送电子邮件为转正/>< / TD>
    < / TR>
    }
< / TBODY>

但是,当我尝试使用这一个,我得到了,说

错误

  

0x800a138f - JavaScript的运行时错误:无法获取属性
  未定义或空引用fnSetData,


这是什么意思?

任何想法,我应该怎么做查询结果使用数据表格式的jQuery观看?

感谢你这么多您的帮助。

下面是我的脚本code:

 <脚本>
    $(函数(){
        $(#示例)的dataTable();
    })
< / SCRIPT>


解决方案

您指定的头9列标题,并在body.I插入10列的值怀疑你忘记添加列header.Add多了一个列在头头标记和检查。

Is there any way how to display the linq query results using the datatable in jquery?

Example:

In my controller:

public ActionResult All_Refers()
    {
        var results = db.rms_referred_vw.ToList();
        return PartialView(results);
    }

In my view:

@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>

But when I try to use this one, I got an error that says

"0x800a138f - JavaScript runtime error: Unable to get property 'fnSetData' of undefined or null reference ,"

What does this mean?

Any idea how should I make the query results be viewed using the datatable format in jquery?

Thank you so much for you help.

Here's my script code:

<script>
    $(function(){
        $("#example").dataTable();
    })
</script>

解决方案

You have specified 9 columns headers in head and inserting 10 column values in the body.I suspect you forget to add a columns header.Add one more columns header in head tag and check.

这篇关于LINQ查询结果以数据表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆