标签:javascript
在一般的BS项目开发中,我们经常需要在前台和后台之间传递数据,mvc架构中,也需要在view和controller之间传递数据,那么我们应该如何实现呢?
view想controller传递数据:view中代码
<li>@Html.ViewComponent().WfSaveLink(Model).Id("saveToLink").OnBeforeDo("externalData")</li> <scriptlanguage="javascript" type="text/javascript"> var externalData = function () { var state =$("#listItem").val(); var explain =$("#TextArea1").val(); if (CheckDataIsNotEmpty(state)&& CheckDataIsNotEmpty(explain)) { $.ajax({ type: "post", url:"@Url.RouteUrl("workflowOperation", new { action ="UpdateModel", controller = "SignQuote" })", data: { state: state, explain: explain, } }); } }; </script>
controller中代码:
Stringstate = QueryString["State"]; Stringexplain = QueryString["explain"];
controller想view中传递数据:
controller数据:
public ActionResultsendRead(string resourceID) { string msg = "数据测试"; return Json(msg,JsonRequestBehavior.AllowGet); }
view中代码:
<scriptlanguage="javascript" type="text/javascript"> var sendReadInfo = function () { $.ajax({ type: "GET", url:"@Url.RouteUrl("workflowOperation", new { action ="sendRead", controller = "SignQuote" })" +"?resourceID=@Model.Data.ID", success: function (s) { if (s) { alert(s) window.location =window.location; } } }); } </script>
mvc如何使用JavaScript在view和controller之间传递数据
标签:javascript
原文地址:http://blog.csdn.net/u010942465/article/details/45370979