Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,
I'm new to ASP.NET though I have a rigid vb.net understanding, I've just read this article AJAX based CRUD tables using ASP.NET MVC 3 and jTable jQuery plug-in[^]
and if I could implement it, I'll finish my project in hours...

but..

here is my code and all I get is a blank page, and the UserList() function isn't called at all.

DemoController.vb
VB
Public Class DemoController
        Inherits System.Web.Mvc.Controller

        Private db As New LernJTableEntities

        '
        ' GET: /Demo

        Function Index() As ActionResult
            Return View()
        End Function

        <HttpPost()>
        Function UserList(Optional jtStartIndex As Integer = 0, Optional jtPageSize As Integer = 0, Optional jtSorting As String = Nothing) As JsonResult
            Try
                'Get data from database
                Dim UserCount = db.User.Count
                 Dim Users As New List(Of User)(db.User.Skip(jtStartIndex).Take(jtPageSize))

                'Return result to jTable
                Return Json(New With {.Result = "OK",
                                      .Records = Users,
                                      .TotalRecordCount = UserCount})
            Catch ex As Exception
                Return Json(New With {.Result = "ERROR",
                                      .Message = ex.Message})
            End Try
        End Function

        <HttpPost()>
        Function DeleteUser() As JsonResult

        End Function

        <HttpPost()>
        Function UpdateUser() As JsonResult

        End Function

        <HttpPost()>
        Function CreateUser() As JsonResult

        End Function



    End Class


Index.vbhtml
Razor
@Code
    ViewData("Title") = "Users"
End Code

<div id="UserTableContainer">
</div>

<script type="text/javascript">

    $(document).ready(function () {

        $('#UserTableContainer').jtable({
            title: 'User List',
            paging: true,
            pageSize: 10,            
            actions: {
                listAction: '@Url.Action("UserList")',
                deleteAction: '@Url.Action("DeleteUser")',
                updateAction: '@Url.Action("UpdateUser")',
                createAction: '@Url.Action("CreateUser")'
            },
            fields: {
                UserId: {
                    key: true,
                    create: false,
                    edit: false,
                    list: false
                },
                Name: {
                    title: 'Name',
                    width: '100%'
                }                
            }
        });

        //Load user list from server
        $('#UserTableContainer').jtable('load');
    });

</script>


and I didn't forgot to put those two in the HEAD section in _Layout.vbhtml
HTML
<link href="@Url.Content("~/jtable/themes/standard/blue/jtable_blue.css")" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/jtable/jquery.jtable.js")"></script>


as it is only my first steps my table [user] consist only two fields {UserId,Name}

What am I missing here?
thank you in advance..
Posted
Updated 4-Aug-12 23:44pm
v4
Comments
Pablo Aliskevicius 5-Aug-12 8:58am    
Do you have a reference to
<script src="/Scripts/jquery-1.6.4.min.js" type="text/javascript"></script>
?
Igal_Berezovsky 5-Aug-12 9:06am    
thanks,
I also needed this one:
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.16.custom.min.js")" type="text/javascript"></script>

Thank you I was clueless

1 solution

Although it seems you got your answer, I want to add, I don't think this is a great way of doing things. It looks like this library is doing some magic hookup stuff for you. MVC will create a CRUD controller for you for free, but overall, you should be writing code that uses a viewmodel, because this will give you a lot more control over what is happening, compared to this, assuming this works.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900