Click here to Skip to main content
15,888,527 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralMessage Closed Pin
2-Apr-13 11:24
professionaljkirkerx2-Apr-13 11:24 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25012-Apr-13 12:35
Jasmine25012-Apr-13 12:35 
AnswerMessage Closed Pin
2-Apr-13 11:36
professionaljkirkerx2-Apr-13 11:36 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25012-Apr-13 12:59
Jasmine25012-Apr-13 12:59 
AnswerRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
jkirkerx2-Apr-13 16:44
professionaljkirkerx2-Apr-13 16:44 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25012-Apr-13 18:34
Jasmine25012-Apr-13 18:34 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
jkirkerx3-Apr-13 6:56
professionaljkirkerx3-Apr-13 6:56 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25013-Apr-13 9:40
Jasmine25013-Apr-13 9:40 
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...

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

C#
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]
		public void Create(object P) {
			//Creates a new Person entity and saves it to the database
			if (P is Person) {
				using (SandboxEntities e = new SandboxEntities()) {
					e.AddToPeople((Person)P);
					e.SaveChanges();
				}
			}
		}

		[WebMethod]
		public void Update(object P) {
			//updates an existing Person entity with new values, and saves to the database
			if (P is Person) {

				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 == ((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.
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
jkirkerx3-Apr-13 10:39
professionaljkirkerx3-Apr-13 10:39 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25013-Apr-13 13:05
Jasmine25013-Apr-13 13:05 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
jkirkerx3-Apr-13 16:03
professionaljkirkerx3-Apr-13 16:03 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25013-Apr-13 18:12
Jasmine25013-Apr-13 18:12 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
jkirkerx3-Apr-13 18:38
professionaljkirkerx3-Apr-13 18:38 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25014-Apr-13 6:44
Jasmine25014-Apr-13 6:44 
QuestionSocial Share Component Pin
Jassim Rahma1-Apr-13 5:43
Jassim Rahma1-Apr-13 5:43 
AnswerRe: Social Share Component Pin
Sandeep Mewara1-Apr-13 6:18
mveSandeep Mewara1-Apr-13 6:18 
GeneralRe: Social Share Component Pin
AspDotNetDev1-Apr-13 6:41
protectorAspDotNetDev1-Apr-13 6:41 
GeneralRe: Social Share Component Pin
Sandeep Mewara1-Apr-13 6:52
mveSandeep Mewara1-Apr-13 6:52 
GeneralRe: Social Share Component Pin
AspDotNetDev1-Apr-13 7:01
protectorAspDotNetDev1-Apr-13 7:01 
GeneralRe: Social Share Component Pin
Sandeep Mewara1-Apr-13 7:20
mveSandeep Mewara1-Apr-13 7:20 
AnswerRe: Social Share Component Pin
AspDotNetDev1-Apr-13 6:40
protectorAspDotNetDev1-Apr-13 6:40 
GeneralRe: Social Share Component Pin
Jassim Rahma1-Apr-13 6:43
Jassim Rahma1-Apr-13 6:43 
GeneralRe: Social Share Component Pin
AspDotNetDev1-Apr-13 6:48
protectorAspDotNetDev1-Apr-13 6:48 
GeneralRe: Social Share Component Pin
Jassim Rahma1-Apr-13 6:55
Jassim Rahma1-Apr-13 6:55 
GeneralRe: Social Share Component Pin
AspDotNetDev1-Apr-13 7:16
protectorAspDotNetDev1-Apr-13 7:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.