Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

c# - linq query results to datatable in View

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...