|
|
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.
|
|
|
|
|
|
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.
|
|
|
|
|
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) {
using (SandboxEntities e = new SandboxEntities()) {
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 pure demo code, then you missing a file for person and people.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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 {
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class SandboxService : System.Web.Services.WebService {
[WebMethod]
public List<Person> Read() {
using (SandboxEntities entity = new SandboxEntities()) {
var q = from p in entity.People select p;
return q.ToList<Person>();
}
}
[WebMethod]
public void Create(object P) {
if (P is Person) {
using (SandboxEntities e = new SandboxEntities()) {
e.AddToPeople((Person)P);
e.SaveChanges();
}
}
}
[WebMethod]
public void Update(object P) {
if (P is Person) {
using (SandboxEntities e = new SandboxEntities()) {
Person pUpdate = (Person)(from p in e.People where p.ID == ((Person)P).ID select p).First();
pUpdate.Phone = ((Person)P).Phone;
pUpdate.FirstName = ((Person)P).FirstName;
pUpdate.LastName = ((Person)P).LastName;
e.SaveChanges();
}
}
}
}
}
Freekin weird if you ask me... I hate it when there's no explanation why two identical things behave differently.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
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.
|
|
|
|
|
Hi,
I have ASP.NET website with C# backend. I would like to ask if you have any idea about a social share component which I can use to allowe users to share the post to the popular social websites such as Facebook, Twitter, Linkedin, etc
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
Pretty sure you don't need OAuth for a generic social sharing component.
|
|
|
|
|
Okay. So, wouldn't the component need authentication in order to push something on wall/tweet? How does the component pass on to social media without account connection?
|
|
|
|
|
I haven't messed with any of this in a few years, but wouldn't you just have to link to the social network with a query string value to the page you intend to like/share (the particular format depending on the social network)? Then, the user can login on that website (if they aren't already logged in). The JavaScript/.Net wouldn't have to do any logging in (because it wouldn't be performing any action on behalf of the user).
|
|
|
|
|
AspDotNetDev wrote: but wouldn't you just have to link to the social network with a query string value to the page you intend to like/share
Sure, if we navigate then yes, this would probably do. I was thinking more from behind the scenes/not navigate.
|
|
|
|
|
|
I am looking for a components but designed for .net with more features
Technology News @ www.JassimRahma.com
|
|
|
|
|
It doesn't need to be designed for .Net. It's just some HTML/JavaScript that can be placed on any webpage (including an ASP.NET webpage).
What features are you looking for that AddThis lacks?
|
|
|
|
|
Well, just getting rid of the AddThis name user will not know it's a components and ut will feel it's part of my website
Also reporting to be saved in a database so Ican show each usur share report for his pages only.
Technology News @ www.JassimRahma.com
|
|
|
|
|
How about shareNice? It's open source, so you can modify it as you like.
Jassim Rahma wrote: Also reporting to be saved in a databas
Is this something you want to log to your database, or should the component have analytics built in? I believe AddThis has analytics of some sort, but I'm not sure about shareNice.
If you use Google Analytics to do click tracking, you can track all client-side clicks on your page (you can do this via JavaScript), regardless of the component.
|
|
|
|
|