Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET MVC3
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
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
@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
<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 4-Aug-12 22:42pm
Edited 4-Aug-12 23:44pm
v4
Comments
Pablo Aliskevicius at 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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,631
1 Sergey Alexandrovich Kryukov 6,345
2 CPallini 5,230
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 5 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100