ASP.NET MVC中從前台整頁模式(View)傳遞資料到後台控制器(Controller)方式

來源:互聯網
上載者:User

標籤:style   io   ar   os   sp   java   on   資料   div   

方式一:

 資料存放區模型Model:此方式未用到資料存放區模型Model,僅簡單的字串string型資料傳遞 前台接收顯示資料檢視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></div> 複製代碼<script type="text/javascript">         $(function () {            $("#submitButton").click(function () {                var data = $(‘#testData‘).val();                $.post("/TransportData/GetFrontViewData", { frontViewData: data }, function () {                    alert("submit data is OK!");                });            });        })       </script>複製代碼幕後處理資料控制器Controller:  複製代碼public class TransportDataController : Controller    {        //        // GET: /TransportData/         public ActionResult Index()        {            return View();        }        public string GetFrontViewData(string frontViewData)        {            //handle frontViewData code             return frontViewData;        }    }複製代碼傳輸中資料樣式:   前台視圖View輸入測試值:     後台控制器Controller獲得此值:     方式二: (借鑒:劉哇勇的部落格) 資料存放區模型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:  複製代碼<div id="container">        <table id="table">            <tr>                <td><label>RTONumber</label><input name="rtoNumber" /></td>                <td><label>Approver</label><input name="approver" /></td>                <td><label>Modifier</label><input name="modifier" /></td>                <td><label>Comment</label><textarea name="comment" cols="30" rows="4"></textarea></td>            </tr>        </table>        <input id="submit" type="button" value="submit"/></div>複製代碼 複製代碼<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: false,                    success: function (data) {                        //window.location.href = "/RequestStatus/RequestDetail?requestID=" + data.RequestID;                        alert("Postting data is over!");                    }                });            });        });</script>複製代碼幕後處理資料控制器Controller:  複製代碼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("");        }     }複製代碼

ASP.NET MVC中從前台整頁模式(View)傳遞資料到後台控制器(Controller)方式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.