码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-04-29 21:47:39      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:javascript

在一般的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>


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

标签:javascript

原文地址:http://blog.csdn.net/u010942465/article/details/45370979

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!