In ASP. net mvc, data is transmitted from the front-end page View to the Controller mode.

Source: Internet
Author: User

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. It only supports simple string data transmission.

Data View displayed on reception desk:

<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>View Code <script type = "text/javascript"> $ (function () {$ ("# submitButton "). click (function () {var data = $ ('# testdata '). val (); $. post ("/TransportData/GetFrontViewData", {frontViewData: data}, function () {alert ("submit data is OK! ") ;}) ;};}) </Script>View Code

Controller for processing data in the background:

Public class TransportDataController: Controller {// GET:/TransportData/public ActionResult Index () {return View ();} public string GetFrontViewData (string frontViewData) {// handle frontViewData code return frontViewData ;}}View Code

Data style during transmission:

Foreground View input test value:

The backend Controller obtains this value:

 

Method 2:

(Reference: Liu wayong's blog)

Data Storage Model:

Public class Model {public string rtoNumber {set; get;} public string approver {set; get;} public string modifier {set; get;} public string comment {set; get ;}}View Code

Data View displayed on reception desk:

<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> Comment </label> <textarea name = "comment" cols = "30" rows = "4"> </textarea> </td> </tr> </table> <input id = "submit" type = "button" value = "submit"/> </div>View 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 ({rtoN Umber: 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: false, success: function (data) {// window. location. href = "/RequestStatus/RequestDetail? RequestID = "+ data. RequestID; alert (" Postting data is over! ") ;}}) ;}); </Script>View Code

Controller for processing data in the background:

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 ("");}}View Code

Data style during transmission:

Foreground View input test value:

The backend Controller obtains this value:

 

I am using it and want to continue writing next time. Thank you! (For errors and defects, please guide)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.