2

I want to extract form parameters, just like in java request.getParameter("blah")

How to do it in C#, presently I serialized my form with jQuery and sending to web method, there I want to extract it

ajax

$("#btn").click(function () {
            alert($('#login').serialize());
            $.ajax({
                type: "POST",
                url: "Default.aspx/Login",
                data: "{'vals': '" + $('#login').serialize() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    TINY.box.show({ html: msg.d, animate: false, close: false, mask: true, boxid: 'success', autohide: 3, top: 200, left: 500 });
                }
            });
        });
    });

code-behind

[WebMethod]
        public static string Login(String vals)
        {
           //WHAT TO DO HERE SO THAT I CAN EXTRACT FROM THAT STRING
          return vals;
        }

I can see the data resurned by msg.d at the client, but thats something like this "uname=1&pwd=2". How to extract it?? please some one help me out. Also is there any way to access the webmethod without making it static?

Corey Adler
  • 15,897
  • 18
  • 66
  • 80
user1573319
  • 69
  • 3
  • 10
  • use json instead of string. or use split('&') and then split('=') you will get the required values. – शेखर Jan 11 '13 at 06:16
  • See what i want is something simple, that can be done without changing the client code and with a single line, I have still hope in c#, there will be some method which can do that, not using strings functions. The data it self is sent as query string, then how can i expect it to be in json format. the data is going like this "uname=1&pwd=2" – user1573319 Jan 11 '13 at 07:04
  • use split function of string http://www.dotnetperls.com/split – शेखर Jan 11 '13 at 07:08
  • Thankyou for ans me. This means the data which ever i am getting to web method is no more in request its just a string? Please give me and example to send and retrive data in json also that wold be great help – user1573319 Jan 11 '13 at 07:11
  • the data should look somethink like this, tell if i am wright. – user1573319 Jan 11 '13 at 07:16
  • [The `.serialize()` method creates a **`text string`** in `standard URL-encoded notation`. It operates on a `jQuery object` representing a `set` of form elements.](http://api.jquery.com/serialize/) – शेखर Jan 11 '13 at 07:19
  • contentType: "application/json; charset=utf-8", dataType: "json" remove these – शेखर Jan 11 '13 at 07:38