Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble

JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble

Scheduled Pinned Locked Moved ASP.NET
javascriptcsharpcssasp-netdatabase
19 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jasmine2501

    Thanks! I did get it figured out. Something to do with the ParameterMap function. I added a basic stringify into that, and now it sends back the proper JSON in the POST request. However, now I'm getting some kind of type conversion problem. The incoming object IS being parsed correctly into a Person object, but then the framework is trying to convert it into a Dictionary object, which fails and throws an exception and a 500 back to the browser. I have no additional information than that, so it's a pretty big mystery at the moment. I think this question is maybe too advanced for this forum. I know there's smart people here like you and me, and I thought this question was interesting enough to attract those folks, but I'm stumped so maybe everybody else is too? If you looked at this question and tried to solve it, please let me know what you found! We might work it out together. This is the Javascript right now - this sends the proper JSON back to the server (and the server even deserializes it correctly to a Person object, then it chokes trying to do something unnecessary).

    $(document).ready(function () {
    $("#PeopleGrid").kendoGrid({
    columns: ["LastName", "FirstName", "Phone"],
    dataSource: {
    transport: {
    read: {
    type: "POST",
    url: "TestKendoGrid.aspx/Read",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
    },
    create: {
    type: "POST",
    url: "TestKendoGrid.aspx/Create",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
    },
    update: {
    type: "POST",
    url: "TestKendoGrid.aspx/Update",
    contentType: "application/json; charset=utf-8",
    dataType: "json"
    },
    parameterMap: function (data, type) {
    return kendo.stringify(data);
    }
    },
    schema: {
    data: "d",
    columns: ["ID", "LastName", "FirstName", "Phone"],
    model: {
    id: "ID",

    J Offline
    J Offline
    jkirkerx
    wrote on last edited by
    #4

    It's hard to get help on certain subjects all year round. Simon is a whiz at this, but haven't seen him around for awhile. So it's failing on the server side web method, or on the client side, parsing the results? Or now calling the web service, the web service fails and the browser goes 500 error? That's usually an object not set to an instance of the object, use the new keyword.

    J 1 Reply Last reply
    0
    • J Jasmine2501

      OK, I'm at my wit's end with this sucker! I basically think I have two options, and both options are doing something screwed up and I can't explain why, but would really just rather have it stop! I'm trying to integrate a KendoUI Grid control, and an ASMX page method. I got the "Read" method to work great - it did take some work to get the JSON running back and forth properly, but it works really nicely. Now, I'm trying to do the "Update" and "Create" methods. The problem is my grid isn't sending back the proper data format. It's sending the right data, but the encoding is screwed up in many different ways depending on how I do it. Here's my JQuery code at the moment...

      function getJson(input) {
      var k = JSON.stringify(input);

      return k;
      

      }

      $(document).ready(function () {
      $("#PeopleGrid").kendoGrid({
      columns: ["LastName", "FirstName", "Phone"],
      dataSource: {
      transport: {
      read: {
      type: "POST",
      url: "TestKendoGrid.aspx/Read",
      contentType: "application/json; charset=utf-8",
      dataType: "json"
      },
      create: {
      type: "POST",
      url: "TestKendoGrid.aspx/Create",
      contentType: "application/json; charset=utf-8",
      dataType: "json"
      },
      update: {
      type: "POST",
      url: "TestKendoGrid.aspx/Update",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      data: function (x) { return getJson(x); }
      }
      },
      schema: {
      data: "d",
      columns: ["ID", "LastName", "FirstName", "Phone"],
      model: {
      id: "ID",
      fields: {
      LastName: {
      editable: true,
      nullable: false
      },
      FirstName: {
      editable: true,
      nullable: false
      },
      Phone: {
      editable: true,
      nullable: false
      }
      }
      }
      },
      batch: false
      },
      editable: {
      update: true,
      create: true,
      destroy: false
      },
      toolbar: ["create", "save", "cancel"]
      })
      });

      The little function at the top is just so I can see the values in the debugger. With the current code, "input" is the actual object I'm trying to send back and "k" actually IS the exact JSON string I want to POST back to my server. Problem is, when I look at what was actually sent, it's funky as hell! This is what the request looks like...

      POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
      Host: localhost:54346
      Connection: keep-alive
      Content-Length: 1930
      Accept: application/json, text/javascript, */*; q=0.01
      O

      J Offline
      J Offline
      jkirkerx
      wrote on last edited by
      #5

      Jasmine2501 wrote:

      And of course, ASP.Net responds to that with a 500 error of "Invalid JSON Primitive" which basically means it choked, according to

      When transmitting JSON, to a web service, the web service can only accept primitive values, like string, integer boolean. Any other value has to be pre-processed first, or else the web service will 500 on you. hmm, Complex objects, which is an object that is not a primitive. I had to write one for ckEditor a while ago, I need to dig it up to find it, but I write in vb, so that may not help. The link below, shows how at the bottom of the article. It takes awhile to soak in the information, but that's how you do it. http://yasintrm.blogspot.com/2012/05/aspnet-ajax-how-to-send-complex-objects.html[^]

      J 1 Reply Last reply
      0
      • J jkirkerx

        It's hard to get help on certain subjects all year round. Simon is a whiz at this, but haven't seen him around for awhile. So it's failing on the server side web method, or on the client side, parsing the results? Or now calling the web service, the web service fails and the browser goes 500 error? That's usually an object not set to an instance of the object, use the new keyword.

        J Offline
        J Offline
        Jasmine2501
        wrote on last edited by
        #6

        It's failing on the server side, but before it gets to my function. It's failing somewhere in the .Net Framework code, because it's trying to turn the Person object into a Dictionary, which is not a conversion that can be done. What I don't understand is why it's trying to do that, when it has a Person object it could pass directly to my function. Something isn't right in the wiring and I don't know what. I'll take a look at the article you posted and see what it's about, but I think I've read it before.

        J 1 Reply Last reply
        0
        • J jkirkerx

          Jasmine2501 wrote:

          And of course, ASP.Net responds to that with a 500 error of "Invalid JSON Primitive" which basically means it choked, according to

          When transmitting JSON, to a web service, the web service can only accept primitive values, like string, integer boolean. Any other value has to be pre-processed first, or else the web service will 500 on you. hmm, Complex objects, which is an object that is not a primitive. I had to write one for ckEditor a while ago, I need to dig it up to find it, but I write in vb, so that may not help. The link below, shows how at the bottom of the article. It takes awhile to soak in the information, but that's how you do it. http://yasintrm.blogspot.com/2012/05/aspnet-ajax-how-to-send-complex-objects.html[^]

          J Offline
          J Offline
          Jasmine2501
          wrote on last edited by
          #7

          BTW, this is the error I'm getting (returned to my page in perfect JSON)

          {
          "Message": "Cannot convert object of type \u0027TestWebSite.Person\u0027 to type \u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\u0027",
          "StackTrace": " at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
          at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
          at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
          at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
          at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)
          at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
          "ExceptionType": "System.InvalidOperationException"
          }

          What is totally stupid about this is, I can debug in the ObjectConverter.ConvertObjectToTypeMain function, and when I inspect the parameter "o" - it is of type "Person" which is exactly what my WebMethod needs. I do not understand why it's trying to convert it to something else at that point.

          J 1 Reply Last reply
          0
          • J Jasmine2501

            It's failing on the server side, but before it gets to my function. It's failing somewhere in the .Net Framework code, because it's trying to turn the Person object into a Dictionary, which is not a conversion that can be done. What I don't understand is why it's trying to do that, when it has a Person object it could pass directly to my function. Something isn't right in the wiring and I don't know what. I'll take a look at the article you posted and see what it's about, but I think I've read it before.

            J Offline
            J Offline
            jkirkerx
            wrote on last edited by
            #8

            Sometimes you have to make sure it's the person object, in which there is no doubt. So if the person object exist in the web method, it may get turned into a different object unless totally specified. So for example, I have a FedEx WSDL with similar names, but one is Version 3 and the other Version 12, If I don't specify Version 12, the web Method thinks it's version 3, in which the enumerators don't match. Rate_Request_V12.PackageType versus Rate_Request_V3.PackageType, I had to add the object in front of the element. The person Object could be the pre-consumer that replaces the primitive value, in which it's not properly registered in the Web Method. The link I gave you shows you how to create an object for per-consumption, as an alternative for a primitive value. I might take the time to investigate further, if my DHL credentials are not registered tonight, the project I'm working on currently.

            1 Reply Last reply
            0
            • J Jasmine2501

              BTW, this is the error I'm getting (returned to my page in perfect JSON)

              {
              "Message": "Cannot convert object of type \u0027TestWebSite.Person\u0027 to type \u0027System.Collections.Generic.IDictionary`2[System.String,System.Object]\u0027",
              "StackTrace": " at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
              at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)
              at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)
              at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)
              at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)
              at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)",
              "ExceptionType": "System.InvalidOperationException"
              }

              What is totally stupid about this is, I can debug in the ObjectConverter.ConvertObjectToTypeMain function, and when I inspect the parameter "o" - it is of type "Person" which is exactly what my WebMethod needs. I do not understand why it's trying to convert it to something else at that point.

              J Offline
              J Offline
              jkirkerx
              wrote on last edited by
              #9

              u0027 is a expected variable in the web method So for example, u0027 would be I think the 1st parameter address_Streetline1

              _
              Public Function submit_ShippingAddress( _
              ByVal address_Streetline1 As String,
              ByVal address_Streetline2 As String,
              ByVal address_City As String,
              ByVal address_State As String,
              ByVal address_Postal As String,
              ByVal address_Country As String,
              ByVal address_Residential As Boolean,
              ByVal secure_Token As String,
              ByVal Localization As Integer) As String

                  Dim json\_response As StringBuilder = New StringBuilder
                  Dim json\_Array As StringBuilder = New StringBuilder
                  Dim dwExitCode As Integer = 2
              
                  Dim m\_Streetline1 As String = HttpUtility.UrlDecode(address\_Streetline1)
                  Dim m\_Streetline2 As String = HttpUtility.UrlDecode(address\_Streetline2)
                  Dim m\_City As String = HttpUtility.UrlDecode(address\_City)
                  Dim m\_State As String = HttpUtility.UrlDecode(address\_State)
                  Dim m\_Postal As String = HttpUtility.UrlDecode(address\_Postal)
                  Dim m\_Country As String = HttpUtility.UrlDecode(address\_Country)
                  Dim m\_Residential As Boolean = address\_Residential
              
                  If (dwExitCode = 0) Then
                      With json\_response
                          .Append("{")
                          .Append(" ""exit\_Code"" : " & dwExitCode & ", ")
                          .Append(" ""address\_City"" : """ & HttpUtility.UrlEncode(m\_City) & """,")
                          .Append(" ""address\_State"" : """ & HttpUtility.UrlEncode(m\_State) & """,")
                          .Append(" ""address\_Postal"" : """ & HttpUtility.UrlEncode(m\_Postal) & """,")
                          .Append(" ""address\_Country"" : """ & HttpUtility.UrlEncode(m\_Country) & """,")
                          .Append(" ""address\_Residential"" : " & m\_Residential.ToString.ToLower & " ")
                          .Append("}")
                      End With
                  Else
                      With json\_response
                          .Append("{")
                          .Append(" ""exit\_Code"" : " & dwExitCode & " ")
                          .Append("}")
                      End With
              
                  End If
              
                  Dim js As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer
                  js.Serialize(json\_response.ToString)
                  js = Nothing
              
                  Return json\_response.ToString
              

              End Function

              Dump the Stringify of the data and go back to basics if you can, and hand build your JSO

              1 Reply Last reply
              0
              • J Jasmine2501

                OK, I'm at my wit's end with this sucker! I basically think I have two options, and both options are doing something screwed up and I can't explain why, but would really just rather have it stop! I'm trying to integrate a KendoUI Grid control, and an ASMX page method. I got the "Read" method to work great - it did take some work to get the JSON running back and forth properly, but it works really nicely. Now, I'm trying to do the "Update" and "Create" methods. The problem is my grid isn't sending back the proper data format. It's sending the right data, but the encoding is screwed up in many different ways depending on how I do it. Here's my JQuery code at the moment...

                function getJson(input) {
                var k = JSON.stringify(input);

                return k;
                

                }

                $(document).ready(function () {
                $("#PeopleGrid").kendoGrid({
                columns: ["LastName", "FirstName", "Phone"],
                dataSource: {
                transport: {
                read: {
                type: "POST",
                url: "TestKendoGrid.aspx/Read",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
                },
                create: {
                type: "POST",
                url: "TestKendoGrid.aspx/Create",
                contentType: "application/json; charset=utf-8",
                dataType: "json"
                },
                update: {
                type: "POST",
                url: "TestKendoGrid.aspx/Update",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: function (x) { return getJson(x); }
                }
                },
                schema: {
                data: "d",
                columns: ["ID", "LastName", "FirstName", "Phone"],
                model: {
                id: "ID",
                fields: {
                LastName: {
                editable: true,
                nullable: false
                },
                FirstName: {
                editable: true,
                nullable: false
                },
                Phone: {
                editable: true,
                nullable: false
                }
                }
                }
                },
                batch: false
                },
                editable: {
                update: true,
                create: true,
                destroy: false
                },
                toolbar: ["create", "save", "cancel"]
                })
                });

                The little function at the top is just so I can see the values in the debugger. With the current code, "input" is the actual object I'm trying to send back and "k" actually IS the exact JSON string I want to POST back to my server. Problem is, when I look at what was actually sent, it's funky as hell! This is what the request looks like...

                POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
                Host: localhost:54346
                Connection: keep-alive
                Content-Length: 1930
                Accept: application/json, text/javascript, */*; q=0.01
                O

                J Offline
                J Offline
                jkirkerx
                wrote on last edited by
                #10

                I've come to the conclusion that KendoGrid is an advanced Jquery Object sort of like CKEditor, and that it has an code interface that is the go between the UI Object, and backend support for creating, updating and deleting records via a web service. Let's take the Web Service first. I suspect that it should be registered on a asmx page, and not aspx page. I don't know if that is your mistake or the way it was packaged from Kendo Dojo as an example.

                TestKendoGrid.asmx/Update

                The following web method takes a non-primitive value. So instead of person being an integer or string, it's an object called person, that must be described somewhere on that page, or somewhere in the project. Person pIn is the non-primitive. Once again, I don't if you wrote this, or if it was provided as a live example, but in order to consume person, it must be pre-consumed first and then consumed, and the object elements must be described somewhere in the web method or a seperate class. So Update returns nothing, no exit code or anything. Only List returns data back as an object called person, and not a JSON String. That why you can't stringify the object. There must be something in the KendoGrid file that parses the Person Object, and updates the KendoGrid. From what I can tell, People is an array or a table, collection, and person is a single record in People.

                [WebMethod]
                public static void Update(Person pIn) {
                //updates an existing Person entity with new values, and saves to the database
                using (SandboxEntities e = new SandboxEntities()) {
                //there should be only one (by definition of PK)
                //but using "First()" is safe in case there is more than one
                Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();

                	pUpdate.Phone = pIn.Phone;
                	pUpdate.FirstName = pIn.FirstName;
                	pUpdate.LastName = pIn.LastName;
                
                	e.SaveChanges();
                }
                

                }

                In my opinion, this is a custom program or solution, made to be easy to use and customized, and that you need to get the example code working first, before making any changes. The Kendo DoJo must have a forum or help source that you can get a better answer from than here. I'm not going to dive into downloading the demo, and setting up a complete project to figure this one out. I deleted my other posts, because they are not relevant to this subject, just misleading for those that follow. Let me know if this is pure demo code, or if you started writing code from scratch to support the Kendo Grid. If it's

                J 2 Replies Last reply
                0
                • J jkirkerx

                  I've come to the conclusion that KendoGrid is an advanced Jquery Object sort of like CKEditor, and that it has an code interface that is the go between the UI Object, and backend support for creating, updating and deleting records via a web service. Let's take the Web Service first. I suspect that it should be registered on a asmx page, and not aspx page. I don't know if that is your mistake or the way it was packaged from Kendo Dojo as an example.

                  TestKendoGrid.asmx/Update

                  The following web method takes a non-primitive value. So instead of person being an integer or string, it's an object called person, that must be described somewhere on that page, or somewhere in the project. Person pIn is the non-primitive. Once again, I don't if you wrote this, or if it was provided as a live example, but in order to consume person, it must be pre-consumed first and then consumed, and the object elements must be described somewhere in the web method or a seperate class. So Update returns nothing, no exit code or anything. Only List returns data back as an object called person, and not a JSON String. That why you can't stringify the object. There must be something in the KendoGrid file that parses the Person Object, and updates the KendoGrid. From what I can tell, People is an array or a table, collection, and person is a single record in People.

                  [WebMethod]
                  public static void Update(Person pIn) {
                  //updates an existing Person entity with new values, and saves to the database
                  using (SandboxEntities e = new SandboxEntities()) {
                  //there should be only one (by definition of PK)
                  //but using "First()" is safe in case there is more than one
                  Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();

                  	pUpdate.Phone = pIn.Phone;
                  	pUpdate.FirstName = pIn.FirstName;
                  	pUpdate.LastName = pIn.LastName;
                  
                  	e.SaveChanges();
                  }
                  

                  }

                  In my opinion, this is a custom program or solution, made to be easy to use and customized, and that you need to get the example code working first, before making any changes. The Kendo DoJo must have a forum or help source that you can get a better answer from than here. I'm not going to dive into downloading the demo, and setting up a complete project to figure this one out. I deleted my other posts, because they are not relevant to this subject, just misleading for those that follow. Let me know if this is pure demo code, or if you started writing code from scratch to support the Kendo Grid. If it's

                  J Offline
                  J Offline
                  Jasmine2501
                  wrote on last edited by
                  #11

                  Oh heck no, this is way beyond the demo code. I've already got the demos working and played with those quite a bit. This is actually just a simple example seeing if I can use the Entity Framework on the back end. We have a considerable project that we are testing the Kendo controls for. So, I wanted to try something simple first. I made a DB-first Entity Framework class for a simple table back in the database. Then I just used what I know about JQuery AJAX and the various blogs I could find, and did this up from scratch. The problem is, since we're not sure we are using Kendo or not, we don't have a license and can't use their 'special' forums, I can only post on here or StackOverflow and stuff. There's a few other ASP.Net developers at my company, but they aren't familiar with the newer stuff like using JQuery and ASP together, or MVC/Razor pages and Entity Framework. So, I'm kinda on my own. I really appreciate you taking the time to think about this for me. I think you've given me some very good ideas to try. I'll just have to give it a go when I get back to the office. I'll let you know how it goes. The ASMX suggestion is a good one - the blog I posted says ASPX page methods work with JQuery AJAX, but it's worth a try on the other method. FYI, the method at the top that returns a List - that does return JSON, as the blog says it can. Anyway thanks again for looking at this, I hope I can help you in the future :) And, your other messages were helpful, you should have left them. Anything that gives me something to think about in a different way moves me forward.

                  J 1 Reply Last reply
                  0
                  • J Jasmine2501

                    Oh heck no, this is way beyond the demo code. I've already got the demos working and played with those quite a bit. This is actually just a simple example seeing if I can use the Entity Framework on the back end. We have a considerable project that we are testing the Kendo controls for. So, I wanted to try something simple first. I made a DB-first Entity Framework class for a simple table back in the database. Then I just used what I know about JQuery AJAX and the various blogs I could find, and did this up from scratch. The problem is, since we're not sure we are using Kendo or not, we don't have a license and can't use their 'special' forums, I can only post on here or StackOverflow and stuff. There's a few other ASP.Net developers at my company, but they aren't familiar with the newer stuff like using JQuery and ASP together, or MVC/Razor pages and Entity Framework. So, I'm kinda on my own. I really appreciate you taking the time to think about this for me. I think you've given me some very good ideas to try. I'll just have to give it a go when I get back to the office. I'll let you know how it goes. The ASMX suggestion is a good one - the blog I posted says ASPX page methods work with JQuery AJAX, but it's worth a try on the other method. FYI, the method at the top that returns a List - that does return JSON, as the blog says it can. Anyway thanks again for looking at this, I hope I can help you in the future :) And, your other messages were helpful, you should have left them. Anything that gives me something to think about in a different way moves me forward.

                    J Offline
                    J Offline
                    jkirkerx
                    wrote on last edited by
                    #12

                    OK! That clarifies things for me. I guess like Richard Says, The first guest is the best guess, and I was on the right track after all. So I deleted messages containing actual help, but after looking at the Kendo Project, I had to back up and question who wrote or modified something that was working. The following JSON, is it going in, or being returned?

                    {
                    "__type": "TestWebSite.Person",
                    "ID": 5,
                    "LastName": "Adamson",
                    "FirstName": "Danielle",
                    "Phone": "303-555-1212",
                    "EntityState": 2,
                    "EntityKey": {
                    "EntitySetName": "People",
                    "EntityContainerName": "SandboxEntities",
                    "EntityKeyValues": [
                    {
                    "Key": "ID",
                    "Value": 5
                    }
                    ],
                    "IsTemporary": false
                    }
                    }

                    You should post the header to the web service, and the 3 web services, can't tell if you have the required attributes needed for Jquery.

                    1 Reply Last reply
                    0
                    • J jkirkerx

                      I've come to the conclusion that KendoGrid is an advanced Jquery Object sort of like CKEditor, and that it has an code interface that is the go between the UI Object, and backend support for creating, updating and deleting records via a web service. Let's take the Web Service first. I suspect that it should be registered on a asmx page, and not aspx page. I don't know if that is your mistake or the way it was packaged from Kendo Dojo as an example.

                      TestKendoGrid.asmx/Update

                      The following web method takes a non-primitive value. So instead of person being an integer or string, it's an object called person, that must be described somewhere on that page, or somewhere in the project. Person pIn is the non-primitive. Once again, I don't if you wrote this, or if it was provided as a live example, but in order to consume person, it must be pre-consumed first and then consumed, and the object elements must be described somewhere in the web method or a seperate class. So Update returns nothing, no exit code or anything. Only List returns data back as an object called person, and not a JSON String. That why you can't stringify the object. There must be something in the KendoGrid file that parses the Person Object, and updates the KendoGrid. From what I can tell, People is an array or a table, collection, and person is a single record in People.

                      [WebMethod]
                      public static void Update(Person pIn) {
                      //updates an existing Person entity with new values, and saves to the database
                      using (SandboxEntities e = new SandboxEntities()) {
                      //there should be only one (by definition of PK)
                      //but using "First()" is safe in case there is more than one
                      Person pUpdate = (Person)(from p in e.People where p.ID == pIn.ID select p).First();

                      	pUpdate.Phone = pIn.Phone;
                      	pUpdate.FirstName = pIn.FirstName;
                      	pUpdate.LastName = pIn.LastName;
                      
                      	e.SaveChanges();
                      }
                      

                      }

                      In my opinion, this is a custom program or solution, made to be easy to use and customized, and that you need to get the example code working first, before making any changes. The Kendo DoJo must have a forum or help source that you can get a better answer from than here. I'm not going to dive into downloading the demo, and setting up a complete project to figure this one out. I deleted my other posts, because they are not relevant to this subject, just misleading for those that follow. Let me know if this is pure demo code, or if you started writing code from scratch to support the Kendo Grid. If it's

                      J Offline
                      J Offline
                      Jasmine2501
                      wrote on last edited by
                      #13

                      LOL, ok... this is a lot of fun... The Create method, which I hadn't tried, works fine! I had to wrap my object in a variable name as mentioned in the article you posted, but it works. The Javascript looks like this now...

                      var svcURL = "SandboxService.asmx";

                      $(document).ready(function () {
                      $("#PeopleGrid").kendoGrid({
                      columns: ["LastName", "FirstName", "Phone"],
                      dataSource: {
                      transport: {
                      read: {
                      type: "POST",
                      url: svcURL + "/Read",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json"
                      },
                      create: {
                      type: "POST",
                      url: svcURL + "/Create",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      data: function (data) { return { P: data }; }
                      },
                      update: {
                      type: "POST",
                      url: svcURL + "/Update",
                      contentType: "application/json; charset=utf-8",
                      dataType: "json",
                      data: function (data) { return { P: data }; }
                      },
                      parameterMap: function (data, type) {
                      return kendo.stringify(data);
                      }
                      },
                      schema: {
                      data: "d",
                      columns: ["ID", "LastName", "FirstName", "Phone"],
                      model: {
                      id: "ID",
                      fields: {
                      LastName: {
                      editable: true,
                      nullable: false
                      },
                      FirstName: {
                      editable: true,
                      nullable: false
                      },
                      Phone: {
                      editable: true,
                      nullable: false
                      }
                      }
                      }
                      },
                      batch: false
                      },
                      editable: {
                      update: true,
                      create: true,
                      destroy: false
                      },
                      toolbar: ["create", "save", "cancel"]
                      })
                      });

                      I did change to ASMX, but the methods basically look the same... Update is still throwing the "Can't convert" error, but Create is not having that problem.

                      using System.Web.Services;
                      using System.Web.Script.Services;
                      using System.ComponentModel;
                      using System.Collections.Generic;
                      using System.Linq;

                      namespace TestWebSite {
                      /// <summary>
                      /// This service does basic CRUD on the Sandbox data
                      /// </summary>
                      [WebService(Namespace = "http://tempuri.org/")]
                      [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
                      [ScriptService]
                      public class SandboxService : System.Web.Services.WebService {
                      [WebMethod]
                      public List<Person> Read() {
                      //Reads the People entity from the database
                      using (SandboxEntities entity = new SandboxEntities()) {
                      var q = from p in entity.People select p;

                      			return q.ToList<Person>();
                      		}
                      	}
                      
                      	\[WebMethod\]
                      	publ
                      
                      J 1 Reply Last reply
                      0
                      • J Jasmine2501

                        LOL, ok... this is a lot of fun... The Create method, which I hadn't tried, works fine! I had to wrap my object in a variable name as mentioned in the article you posted, but it works. The Javascript looks like this now...

                        var svcURL = "SandboxService.asmx";

                        $(document).ready(function () {
                        $("#PeopleGrid").kendoGrid({
                        columns: ["LastName", "FirstName", "Phone"],
                        dataSource: {
                        transport: {
                        read: {
                        type: "POST",
                        url: svcURL + "/Read",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json"
                        },
                        create: {
                        type: "POST",
                        url: svcURL + "/Create",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: function (data) { return { P: data }; }
                        },
                        update: {
                        type: "POST",
                        url: svcURL + "/Update",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        data: function (data) { return { P: data }; }
                        },
                        parameterMap: function (data, type) {
                        return kendo.stringify(data);
                        }
                        },
                        schema: {
                        data: "d",
                        columns: ["ID", "LastName", "FirstName", "Phone"],
                        model: {
                        id: "ID",
                        fields: {
                        LastName: {
                        editable: true,
                        nullable: false
                        },
                        FirstName: {
                        editable: true,
                        nullable: false
                        },
                        Phone: {
                        editable: true,
                        nullable: false
                        }
                        }
                        }
                        },
                        batch: false
                        },
                        editable: {
                        update: true,
                        create: true,
                        destroy: false
                        },
                        toolbar: ["create", "save", "cancel"]
                        })
                        });

                        I did change to ASMX, but the methods basically look the same... Update is still throwing the "Can't convert" error, but Create is not having that problem.

                        using System.Web.Services;
                        using System.Web.Script.Services;
                        using System.ComponentModel;
                        using System.Collections.Generic;
                        using System.Linq;

                        namespace TestWebSite {
                        /// <summary>
                        /// This service does basic CRUD on the Sandbox data
                        /// </summary>
                        [WebService(Namespace = "http://tempuri.org/")]
                        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
                        [ScriptService]
                        public class SandboxService : System.Web.Services.WebService {
                        [WebMethod]
                        public List<Person> Read() {
                        //Reads the People entity from the database
                        using (SandboxEntities entity = new SandboxEntities()) {
                        var q = from p in entity.People select p;

                        			return q.ToList<Person>();
                        		}
                        	}
                        
                        	\[WebMethod\]
                        	publ
                        
                        J Offline
                        J Offline
                        jkirkerx
                        wrote on last edited by
                        #14

                        Yah, your consuming the object P now, you should be able to walk through the code by loading the web service class file, or file, and set a break-point on update, to see if the using entity code is throwing an exception. But I'm sure you thought of that already. Indian123 was working with the entity framework and web services about 6 months ago, haven't seen him around for awhile now. I downloaded the demo, and I can you have a ton of time in this beyond what they ship. I'm not running anything capable of HTML 5 right now, till I upgrade.

                        J 1 Reply Last reply
                        0
                        • J jkirkerx

                          Yah, your consuming the object P now, you should be able to walk through the code by loading the web service class file, or file, and set a break-point on update, to see if the using entity code is throwing an exception. But I'm sure you thought of that already. Indian123 was working with the entity framework and web services about 6 months ago, haven't seen him around for awhile now. I downloaded the demo, and I can you have a ton of time in this beyond what they ship. I'm not running anything capable of HTML 5 right now, till I upgrade.

                          J Offline
                          J Offline
                          Jasmine2501
                          wrote on last edited by
                          #15

                          Thanks again for all your help! I kinda got it to work. It's working with a Dictionary though, which isn't going to work long term, but at least it's not a total loss. I don't know if we'll use this method knowing that I'll have to write a lot of custom code for each table. We were hoping to just generate a lot of code, and if we can't do that, it isn't very much value to change from what we're doing now. The Kendo Grid is a little more interactive, but if the overhead to get that is "write custom classes in javascript for every object" then it defeats the purpose of using the EF stuff, kinda. We did decide to pay for the license though, mainly for the support. I've spent more time on this already, than what the license costs.

                          J 1 Reply Last reply
                          0
                          • J Jasmine2501

                            Thanks again for all your help! I kinda got it to work. It's working with a Dictionary though, which isn't going to work long term, but at least it's not a total loss. I don't know if we'll use this method knowing that I'll have to write a lot of custom code for each table. We were hoping to just generate a lot of code, and if we can't do that, it isn't very much value to change from what we're doing now. The Kendo Grid is a little more interactive, but if the overhead to get that is "write custom classes in javascript for every object" then it defeats the purpose of using the EF stuff, kinda. We did decide to pay for the license though, mainly for the support. I've spent more time on this already, than what the license costs.

                            J Offline
                            J Offline
                            jkirkerx
                            wrote on last edited by
                            #16

                            I'm pretty conservative now days with using 3rd party stuff. I've wasted too much much time in my life trying to make things work, like that Javascript from a customer project that was a total joke, a wordpress plugin that didn't work as expected, so I rewrote it from scratch and posted it as a tip/trick. I looked at the Kendo demo, it looks nice, pretty, but I could of wrote my own from scratch in a in a week, that would do what I need it to do, and easy to understand and support. Let somebody younger figure it out and preserve your work.

                            J 1 Reply Last reply
                            0
                            • J jkirkerx

                              I'm pretty conservative now days with using 3rd party stuff. I've wasted too much much time in my life trying to make things work, like that Javascript from a customer project that was a total joke, a wordpress plugin that didn't work as expected, so I rewrote it from scratch and posted it as a tip/trick. I looked at the Kendo demo, it looks nice, pretty, but I could of wrote my own from scratch in a in a week, that would do what I need it to do, and easy to understand and support. Let somebody younger figure it out and preserve your work.

                              J Offline
                              J Offline
                              Jasmine2501
                              wrote on last edited by
                              #17

                              Yeah I know what you mean, but sometimes that stuff can really help keep you on schedule too. I've had great luck with things like DotNetNuke and Joomla, and most JQuery stuff works like it should. But you are right, I could have met the requirements with Webforms or MVC last week. I will figure it out eventually. If I had a blog I might write it up, but I never seem to have time for that stuff.

                              J 1 Reply Last reply
                              0
                              • J Jasmine2501

                                Yeah I know what you mean, but sometimes that stuff can really help keep you on schedule too. I've had great luck with things like DotNetNuke and Joomla, and most JQuery stuff works like it should. But you are right, I could have met the requirements with Webforms or MVC last week. I will figure it out eventually. If I had a blog I might write it up, but I never seem to have time for that stuff.

                                J Offline
                                J Offline
                                jkirkerx
                                wrote on last edited by
                                #18

                                Well you ahead of the curve on me, I haven't tried MVC yet, I'm old an I remember Microsoft saying VB will no longer be supported, oh back in 99. So I'm skeptical on tech stuff from Microsoft. late here, need to go home and watch the Americans. I think I remember you posting some questions last year, or knocking out some answers.

                                J 1 Reply Last reply
                                0
                                • J jkirkerx

                                  Well you ahead of the curve on me, I haven't tried MVC yet, I'm old an I remember Microsoft saying VB will no longer be supported, oh back in 99. So I'm skeptical on tech stuff from Microsoft. late here, need to go home and watch the Americans. I think I remember you posting some questions last year, or knocking out some answers.

                                  J Offline
                                  J Offline
                                  Jasmine2501
                                  wrote on last edited by
                                  #19

                                  Yeah it depends on what kind of job I have. This site was blocked at my last company - high security there, working on stuff for the defense department.

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • World
                                  • Users
                                  • Groups