在一般的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" })" +"[email protected]", success: function (s) { if (s) { alert(s) window.location =window.location; } } }); } </script>
时间: 2024-10-18 08:13:49