程序员人生 网站导航

mvc如何使用JavaScript在view和controller之间传递数据

栏目:htmlcss时间:2015-06-09 08:25:46

在1般的BS项目开发中,我们常常需要在前台和后台之间传递数据,mvc架构中,也需要在viewcontroller之间传递数据,那末我们应当如何实现呢?

        viewcontroller传递数据: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"];

 

controllerview中传递数据:

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>


------分隔线----------------------------
------分隔线----------------------------

最新技术推荐