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

ASP.NET

 
AnswerRe: Reading an HTML file into XmlDocument object Pin
Richard Deeming3-Apr-13 3:42
mveRichard Deeming3-Apr-13 3:42 
QuestionAdding dll in web application which is developing on MVC Framework Pin
Shree.grace1-Apr-13 19:41
Shree.grace1-Apr-13 19:41 
AnswerRe: Adding dll in web application which is developing on MVC Framework Pin
Jasmine25012-Apr-13 18:41
Jasmine25012-Apr-13 18:41 
GeneralRe: Adding dll in web application which is developing on MVC Framework Pin
Shree.grace2-Apr-13 19:02
Shree.grace2-Apr-13 19:02 
GeneralRe: Adding dll in web application which is developing on MVC Framework Pin
Jasmine25013-Apr-13 5:47
Jasmine25013-Apr-13 5:47 
GeneralRe: Adding dll in web application which is developing on MVC Framework Pin
Shree.grace3-Apr-13 18:23
Shree.grace3-Apr-13 18:23 
GeneralRe: Adding dll in web application which is developing on MVC Framework Pin
Jasmine25014-Apr-13 6:39
Jasmine25014-Apr-13 6:39 
QuestionJQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25011-Apr-13 11:06
Jasmine25011-Apr-13 11:06 
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...
JavaScript
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
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti

0=%7B&1=%22&2=_&3=_&4=t&5=y&6=p&7=e&8=%22&9=%3A&10=%22&11=T&12=e&13=s
&14=t&15=W&16=e&17=b&18=S&19=i&20=t&21=e&22=.&23=P&24=e&25=r&26=s&27=o
&28=n&29=%22&30=%2C&31=%22&32=I&33=D&34=%22&35=%3A&36=5&37=%2C&38=%22&39=L
&40=a&41=s&42=t&43=N&44=a&45=m&46=e&47=%22&48=%3A&49=%22&50=A&51=d&52=a
&53=m&54=s&55=o&56=n&57=%22&58=%2C&59=%22&60=F&61=i&62=r&63=s&64=t&65=N
&66=a&67=m&68=e&69=%22&70=%3A&71=%22&72=D&73=a&74=n&75=i&76=e&77=l&78=l
&79=e&80=%22&81=%2C&82=%22&83=P&84=h&85=o&86=n&87=e&88=%22&89=%3A&90=%22
&91=3&92=0&93=3&94=-&95=5&96=2&97=3&98=-&99=8&100=7&101=1&102=9&103=%22
&104=%2C&105=%22&106=E&107=n&108=t&109=i
&110=t&111=y&112=S&113=t&114=a&115=t&116=e&117=%22&118=%3A&119=2&120=%2C
&121=%22&122=E&123=n&124=t&125=i&126=t&127=y&128=K&129=e&130=y&131=%22&132=%3A
&133=%7B&134=%22&135=E&136=n&137=t&138=i&139=t&140=y&141=S&142=e&143=t&144=N
&145=a&146=m&147=e&148=%22&149=%3A&150=%22&151=P&152=e&153=o&154=p&155=l
&156=e&157=%22&158=%2C&159=%22&160=E&161=n&162=t&163=i&164=t&165=y&166=C
&167=o&168=n&169=t&170=a&171=i&172=n&173=e&174=r&175=N&176=a&177=m&178=e
&179=%22&180=%3A&181=%22&182=S&183=a&184=n&185=d&186=b&187=o&188=x&189=E&190=n
&191=t&192=i&193=t&194=i&195=e&196=s&197=%22&198=%2C&199=%22&200=E&201=n&202=t
&203=i&204=t&205=y&206=K&207=e&208=y&209=V&210=a&211=l&212=u&213=e&214=s
&215=%22&216=%3A&217=%5B&218=%7B&219=%22&220=K&221=e&222=y&223=%22&224=%3A&225=%22
&226=I&227=D&228=%22&229=%2C&230=%22&231=V&232=a&233=l&234=u&235=e&236=%22
&237=%3A&238=5&239=%7D&240=%5D&241=%2C&242=%22&243=I&244=s&245=T&246=e&247=m&248=p
&249=o&250=r&251=a&252=r&253=y&254=%22&255=%3A&256=f&257=a&258=l&259=s&260=e
&261=%7D&262=%7D&__type=TestWebSite.Person&ID=5&LastName=Adamson&FirstName=Danielle&Phone=303-555-1212&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=5&EntityKey%5BIsTemporary%5D=false



LOL, wut?! It's encoding each character as if it's a separate parameter! What in the hell?!

If I don't "stringify" it posts the data as URL-encoded, like this:

POST http://localhost:54346/TestKendoGrid.aspx/Update HTTP/1.1
Host: localhost:54346
Connection: keep-alive
Content-Length: 320
Accept: application/json, text/javascript, */*; q=0.01
Origin: http://localhost:54346
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31
Content-Type: application/json; charset=UTF-8
Referer: http://localhost:54346/TestKendoGrid.aspx
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=dkmbybyaz0bitvat2wbdueti

__type=TestWebSite.Person&ID=18&LastName=Russell&FirstName=Graham&Phone=303-555-5000&EntityState=2&EntityKey%5BEntitySetName%5D=People&EntityKey%5BEntityContainerName%5D=SandboxEntities
&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BKey%5D=ID&EntityKey%5BEntityKeyValues%5D%5B0%5D%5BValue%5D=18&EntityKey%5BIsTemporary%5D=false



And of course, ASP.Net responds to that with a 500 error of "Invalid JSON Primitive" which basically means it choked, according to http://encosia.com/asmx-scriptservice-mistake-invalid-json-primitive/[^]

So, I'm trying to follow the advice in the article, but that's causing the really weird request in the first snippet. So, I'm not sure what to do!

It should be posting this (the value of "k" in the little function):
{"__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}}


My WebMethod on the receiving side is here - the Read method works great, but the other two haven't even seen a proper request so I'm not sure if they are correct yet.

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

[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();
	}
}


I've dug myself a big hole here, please help me get out! TIA Smile | :)

modified 1-Apr-13 19:19pm.

AnswerMessage Closed Pin
2-Apr-13 7:14
professionaljkirkerx2-Apr-13 7:14 
GeneralRe: JQuery/JSON/ASP.Net/AJAX/Entity Framework trouble Pin
Jasmine25012-Apr-13 11:16
Jasmine25012-Apr-13 11:16 
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 
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 

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.