In ASP. net mvc, data is transmitted from the front-end page View to the Controller mode.
Method 1:
Data storage Model: This method does not use the data storage Model. Only the simple string-type data is transmitted to the front-end and the data View is displayed. View: <div style = "height: 300px; width: 100% "> <div style =" margin-left: 100px; margin-top: 50px; "> <input id =" testData "type =" text "style =" width: 200px; "/> <br/> <input id =" submitButton "type =" button "style =" height: 25px; width: 75px; margin-top: 35px; "value =" submit "> </div> copy the Code <script type =" text/javascript "> $ (function () {$ (" # submitButt On "). click (function () {var data = $ ('# testdata '). val (); $. post ("/TransportData/GetFrontViewData", {frontViewData: data}, function () {alert ("submit data is OK! ") ;}) ;};}) </Script> copy the code background processing data Controller: copy the code public class TransportDataController: Controller {/// GET: /TransportData/public ActionResult Index () {return View ();} public string GetFrontViewData (string frontViewData) {// handle frontViewData code return frontViewData;} copy the data style during code transmission: frontend View input test value: the backend Controller obtains this value: Method 2: (reference: Liu wayong's blog) data storage Model: copy the code public class Model {public st Ring rtoNumber {set; get;} public string approver {set; get;} public string modifier {set; get;} public string comment {set; get ;}} copy the code to the front-end to receive and display the Data View: copy the Code <div id = "container"> <table id = "table"> <tr> <td> <label> RTONumber </label> <input name = "rtoNumber "/> </td> <label> Approver </label> <input name = "approver"/> </td> <label> Modifier </label> <input name = "modifier"/> </td> <label> Comm Ent </label> <textarea name = "comment" cols = "30" rows = "4"> </textarea> </td> </tr> </table> <input id = "submit" type = "button" value = "submit"/> </div> copy the code and copy the Code <script type = "text/javascript" >$ (function () {$ ('# submit '). click (function () {var model = []; var subModel = []; $. each ($ ("table tr"), function (I, item) {var RTONumber = $ (item ). find ("[name = rtoNumber]"). val (); var Approver = $ (item ). find ("[name = Approver] "). val (); var Modifier = $ (item ). find ("[name = modifier]"). val (); var Comment = $ (item ). find ("[name = comment]"). val (); model. push ({rtoNumber: RTONumber, approver: Approver, modifier: Modifier, comment: Comment, checkBoxValue: subModel}); $. ajax ({url: '/TransportModelData/getmodelinfo', data: JSON. stringify (model), type: 'post', contentType: 'application/json; charset = UTF-8 ', async: fa Lse, success: function (data) {// window. location. href = "/RequestStatus/RequestDetail? RequestID = "+ data. RequestID; alert (" Postting data is over! ") ;}}) ;};}); </Script> copy the code background processing data Controller: copy the code public class TransportModelDataController: Controller {/// GET: /TransportModelData/public ActionResult Index () {return View ();} public ActionResult getModelInfo (List <Model> model) {string rtoNumber = model [0]. rtoNumber; string modifier = model [0]. modifier; string comment = model [0]. comment; string approver = model [0]. approver; return Content ("") ;}} copy the code