The effect is as follows:
Click Submit to insert the data in the text box to the database.
Page SectionCode:
Jquery code:
$ ( Function () {$ ( "# Sendmsg"). Click ( Function () {// Triggered $. Ajax ({type: "Post" , URL: "/MSG/sendmicromsg /" , // Send to sendmicromsg action in msgcontroller. Datatype: "JSON" , Data :{ "Content": $ ("# contents"). Val ()}, // Insert the text in the "contents" ID to the database success: Function (Data) {// returned data. Alert (data ); }, Error: Function (Error) {alert ( "Error" ); }}); Return False ;});});
The following describes how to obtain parameters for the Controller:
// /<Summary> // /Send Weibo messages // /</Summary> Public actionresult sendmicromsg (formcollection frmcollection) {isession _ Session = SM. getsession (); string content = Frmcollection ["content" ]. Tostring (); // obtain the parameters passed by Ajax. You don't need to worry about other code. Now you know that the parameter is obtained. Write your inserted data. Trule = New Trule (_ session); trule. Post (content, userrule. getcurrentuserid ()); Return JSON (content); // here I can also return an object, or a piece of spliced HTML code: returned object: joson (New trule {id = 4, name = ""});}
Is the effect of clicking submit: