如何使用jquery和mvc2在页面之间保留控制输入值

时间:2012-10-11 06:39:50

标签: jquery asp.net-mvc-2

这是我的问题..

我正在使用jquery和mvc2。我选择或写入输入控件中的值,如复选框或文本框或下拉菜单,然后我移动到下一页,然后我回到相同的页面,我需要选中复选框或具有值的文本框..how我能做到吗

维护页面之间的输入控制值 提前谢谢

    #region TableHeaderOnStart
    public string TableHeaderOnStart()
    {
        string TableHeaderValues = string.Empty;
        try
        {
        TableHeaderValues = TheadShipTo + "," + TheadCountry + "," + TheadNotes + "," + TheadShipStatus + "," + TheadStoreName + "," + TheadRSM;
        }
        catch (Exception ex)
        {
            TableHeaderValues = string.Empty;
            Logger.WriteToLog(Logger.LogType.Error, Constant.strmerchantname, Constant.struser, "OrderController.TableHeaderValues()", ex.Message, null, null);
        }
        return TableHeaderValues;
    }
    #endregion

    #region TableHeaders
    public void TableHeaders(bool ShipTo, bool Country, bool Notes, bool ShipStatus, bool StoreName, bool RSM)
    {
        TheadShipTo = ShipTo;
        TheadCountry = Country;
        TheadNotes = Notes;
        TheadShipStatus = ShipStatus;
        TheadStoreName = StoreName;
        TheadRSM = RSM;
    }
    #endregion

父视图的控制器页面中的上述代码... 下面的代码是针对父视图..在jquery ....几乎我得到了它....

     jQuery(document).ready(function ($) {
        $('#thetable1').tableScroll({ height: 100 });
        $('#table').tableScroll({ height: 100 });
        $('#thetable3').tableScroll({ height: 100 });


        var Url = '<%: Url.Action("TableHeaderOnStart", "Orders") %>';
        $.ajax({
            cache: false,
            type: "POST",
            url: Url,
            data: "",
            dataType: "HTML",
            success: function (data) {

                var Header = data.split(',');

                if (Header[0] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Ship To')").show();
                        jQuery("#jqTable").showCol("Ship To")
                    });
                    $('#SHIPTO').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Ship To')").hide();
                        jQuery("#jqTable").hideCol("Ship To")
                    });
                    $('#SHIPTO').attr('checked', false);
                }

                if (Header[1] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Country')").show();
                        jQuery("#jqTable").showCol("Country")
                    });
                    $('#COUNTRY').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Country')").hide();
                        jQuery("#jqTable").hideCol("Country")
                    });
                    $('#COUNTRY').attr('checked', false);
                }

                if (Header[2] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Notes')").show();
                        jQuery("#jqTable").showCol("Notes")
                    });
                    $('#NOTES').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Notes')").hide();
                        jQuery("#jqTable").hideCol("Notes")
                    });
                    $('#NOTES').attr('checked', false);
                }

                if (Header[3] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Ship Status')").show();
                        jQuery("#jqTable").showCol("Ship Status")
                    });
                    $('#SHIPSTATUS').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Ship Status')").hide();
                        jQuery("#jqTable").hideCol("Ship Status")
                    });
                    $('#SHIPSTATUS').attr('checked', false);
                }

                if (Header[4] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Store Name')").show();
                        jQuery("#jqTable").showCol("Store Name")
                    });
                    $('#STORENAME').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('Store Name')").hide();
                        jQuery("#jqTable").hideCol("Store Name")
                    });
                    $('#STORENAME').attr('checked', false);
                }

                if (Header[5] == 'True') {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('RequestedShipMethod')").show();
                        jQuery("#jqTable").showCol("RequestedShipMethod")
                    });
                    $('#RSM').attr('checked', true);
                }
                else {
                    $('#jqTable tr').each(function () {
                        $(this).find("td:contains('RequestedShipMethod')").hide();
                        jQuery("#jqTable").hideCol("RequestedShipMethod")
                    });
                    $('#RSM').attr('checked', false);
                }

            },
            error: function (xhr, ajaxOptions, thrownError) {
                if (xhr.status == 403) {
                    window.location.href = '<%: Url.Action( "SessionExpire", "Home" ) %>';
                }
            }
        });

        //window.onbeforeunload = function () {
        $(window).unload(function () {
            var SHIPTO = document.getElementById('SHIPTO').checked;
            var COUNTRY = document.getElementById('COUNTRY').checked;
            var NOTES = document.getElementById('NOTES').checked;
            var SHIPSTATUS = document.getElementById('SHIPSTATUS').checked;
            var STORENAME = document.getElementById('STORENAME').checked;
            var RSM = document.getElementById('RSM').checked;

            var Url = '<%: Url.Action("TableHeaders", "Orders") %>';
            $.ajax({
                cache: false,
                type: "POST",
                url: Url,
                data: "ShipTo=" + SHIPTO + "&Country=" + COUNTRY + "&Notes=" + NOTES + "&ShipStatus=" + SHIPSTATUS + "&StoreName=" + STORENAME + "&RSM=" + RSM,
                dataType: "HTML",
                success: function (data) {
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    if (xhr.status == 403) {
                        window.location.href = '<%: Url.Action( "SessionExpire", "Home" ) %>';
                    }
                }
            });
            return false;
        });

1 个答案:

答案 0 :(得分:0)

我想当你点击已经渲染的视图上的“下一步”链接时,你正在调用另一个动作方法来渲染你的下一个视图。您应该将您的值从父视图发布到下一视图,将您的文本框值,复选框存储在父视图的Controller操作方法中的会话变量中,然后将控件传递给下一视图的操作方法...渲染...

当您再次调用此视图上的“返回链接”按钮时。调用您的父视图的控制器操作方法,该方法将使您的父视图呈现已存在的文本框值,复选框就像您之前已将它们存储在会话变量中一样...

如果您可以提供一些代码,那么很容易帮助您解决更多问题