First, we'll introduce a JSON script in the foreground to facilitate the serialization of the JS object
<script type= "Text/javascript" src= "/js/jquery.json-2.4.min.js" ></script>
Then we declare a class in the foreground, put the value you want to save into the class, and finally serialize
Copy Code code as follows:
function Save () {
var examid = ' <%=examid%> ';
var yearterm = $ ("#<%=ddlyearterm.clientid%>"). Val ();
var Examtype = $ ("#<%=ddlexamtype.clientid%>"). Val ();
var examdate = $ ("#ExamDate"). Val ();
var examname = $ ("#ExamName"). Val ();
var exam = {};
exam["Examid"] = Examid;
exam["yearterm"] = yearterm;
exam["Examtype"] = Examtype;
exam["examdate"] = examdate;
exam["examname"] = Examname;
var json = $.tojson (exam);
var result = Ajaxcontroller.editexam (JSON). value;
if (result = = "Success")
{
Alert ("Save Success");
Parent.$.fancybox.close ();
}
Else
{
alert (result);
}
}
Then we are in the background, deserialization, and using the value. Because we use Ajax, we have to add [Ajax.ajaxmethod] features to the backend method and add Ajax to the CS of your front page. Look at the specific use
How to use Microsoft Ajax Library (Ajax.ajaxmethod) http://www.jb51.net/article/40764.htm
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax (typeof (Youjiao.xxt.BLL.Controller.AjaxController));
if (! IsPostBack)
{
Databind ();
}
}
Copy Code code as follows:
[Ajax.ajaxmethod]
public string Editexam (string value)
{
string result = "";
Try
{
if (HttpContext.Current.Request.IsAuthenticated)
{
Editexam Editexam = jsonserializehelper.deserializefromjson<editexam> (value);
Examcontroller Econtroller = new Examcontroller ();
Econtroller.editexam (Editexam);
result = "Success";
}
Else
{
result = "Session is invalid, please login again!" ";
}
}
catch (Exception ex)
{
result = ex. message;
}
return result;
}
Image:
Copy Code code as follows:
[Serializable]
public class Editexam
{
public string Examid {get; set;}
public string Yearterm {get; set;}
public string Examtype {get; set;}
public string Examdate {get; set;}
public string Examname {get; set;}
}
This can be very good to avoid in the foreground JS inside a large number of parameters, the background can be directly deserialized to the class to point out the value of the member