Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
697 views
in Technique[技术] by (71.8m points)

asp.net mvc 3 - Sending JSON object to the server via http GET

I am looking for sending JSON object to the server via GET. Chris's answer on Post an Array of Objects via JSON to ASP.Net MVC3 works for the http POST but not for GET. My case also works for POST but not for GET. What can I do to make GET work Here is my case: in Controller I have the following method public ActionResult Screenreport(Screentable screendata)

   {
       // do something here
       return View();
   }

I have two ModelView as follows:

   public class Screenrecord
   {
      public string Firstname{ get; set; }
      public string Lastname{ get; set; }
   }
   public class Screentable
   {
      public List<Screenrecord> Screenlist { get; set; } 
   }

On the client side I generate JSON object

var Screentable = { Screenlist: screendata };

screendata is an array of Screenrecord

All this work when I use POST but when I use GET I am getting null value (screendata = null) Controllers' method. In other word when click GO, screendata is null in Screenreport(Screentable screendata) routine.

Also, if I send one JSON object it works but if I send an array (list) like I described, it does not. Is what I am trying to do doable?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No :-) Thats not how get works.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

(see 9.3 GET)

"The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI"

Request-URI being the important part here. There is no concept of body data in a GET request.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...