0

I have a form on my website which collects data and posts using jquery to be handled using c#. I use request.form to capture the form data.

My friend said to create a JavaScript object to pass the data through instead of loads of variables. My problem is when you post an object with value pairs how do you get c# to obtain the values from the object because I can't seem to use request.form now.

1
  • 1
    Could you post some code? I would think that it always send it as "post" values, which you should be able to get it with request.form. Commented Apr 17, 2012 at 18:39

5 Answers 5

3

Have you looked at JSON.Net? That makes JSON (de)serialization pretty easy

Sign up to request clarification or add additional context in comments.

Comments

1

Json.js has Stringify() which convert your js object to Json String so in C# you can deserialize this string back to an object

Comments

1

.NET has a built in JavaScript (i.e. JSON) serializer. It is in System.Web.Extensions.

 JavaScriptSerializer serializer = new JavaScriptSerializer();

 // To serialize
 Dictionary<string, object> test = new Dictionary<string, object>(){ { "a", 1 } };
 string json = serializer.Serialize(test);

 // To deserialize (convert back to a .NET object)
 Dictionary<string, object> result = serializer.Deserialize<Dictionary<string, object>>(json);

Comments

0

You can use 1 hidden field and put a JSON value/pair string in that field and then parse it server-side.

Comments

0

I have managed to fix the issue. When posting the data I had to use Request instead of Request.Form. Now the values are being passed back. Sorry if I did not include any code and I think the question I asked was a bit ambiguous.

1 Comment

You should accept your answer so people know this question is resolved.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.