I am posting a json object to an ASP.Net MVC controller with C# code. To keep things simple in this example the object is just a car with make and model properties. Everything works well with the code below. My question is - how would I post multiple parameters? For example, how would I post a JSON object, an email address, and a phone number?
//post to form
string requestData = "{\"Make\":\"Ford\",\"Model\":\"Mustang\"}";
byte[] data = Encoding.UTF8.GetBytes(requestData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://receiving.url/showdata");
request.Method = "POST";
request.ContentType = "application/json";
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
string result = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.Write(result);
Here is the Controller code that retrieves the json object from the post, and then outputs the json for verification purposes.
[HttpPost]
public JsonResult showdata(Car c)
{
return Json(c, JsonRequestBehavior.AllowGet);
}
I'm looking to do something like this:
[HttpPost]
public JsonResult showdata(Car c, string email, string phone)
{
return Json(c, JsonRequestBehavior.AllowGet);
}