C # front end of the rear receiving various types of data

 Common way to submit data back end so the front end of three kinds: 1.form submitted; 2.url submitted parameters; 3.json Submit

1. For way to submit a form form

Request.Form used at the rear end receiving mode, such as

   Front-end code fragment:

 var businesstypes = $("#businesstypes").val();
 if (businesstypes == null || businesstypes == '') return;
 var value = $("form").serialize();
 $.post('@Url.Action("BatchPublish")', value, function (data) 
{
  ....
} 

  Back-end code fragment:

 FormCollection form = new FormCollection(Request.Unvalidated().Form);
 string businestypes = form["businesstypes"];

  2. For json case

Front-end code:

var rst = JSON.stringify(object xxx);
$.post(posturl, rst, function (data) {...}

Back-end code:

using (StreamReader stream = new System.IO.StreamReader(Request.InputStream))
{
string Jsonobj = stream.ReadToEnd();
var MeEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<MenuEntity>(Jsonobj);
}

  3. For Url inside the parameters, this is generally used in the Get. Several of the above is to say the situation POST;

Get way to use Request.QueryString get can be very simple

Guess you like

Origin www.cnblogs.com/walt/p/11298037.html