页面未重定向,MVC

时间:2018-08-10 14:05:14

标签: javascript asp.net-mvc

我目前正在MVC上的一个项目上工作,需要将数据从视图传递到控制器,所以我已经使用ajax完成了此操作,但是单击按钮(将触发值发送到控制器)后,页面无法重定向到下一页(从reservation_step_1到reservation_step_2),它什么也不做,但是该值传递给相应的控制器操作(由reservation_step_1接收并发送到reservation_step_2)。

我的控制器动作:

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult reservation_step_1(string x)
    {
        string val = x;
        return RedirectToAction("reservation_step_2", "Home", new { val = val });
    }

    [HttpGet]
    public ActionResult reservation_step_2(string val)
    {
        string rat = val;
        ViewBag.totda = rat;
        return View();
    }

我的观点:

<body>
    <img src="~/images/maxresdefault.jpg" style="width:1457px; height:325px; margin-left: -160px;" />
    <br />
    <br />
    <br />
    <table class="table">
        @foreach (var item in Model)
        {
            {
            <div class="tabcolumn-container" style="height: 90px; border: 1px solid grey">

                <div class="tabcolumn30 frame" style="margin-top: 0px; margin-bottom: 0px;">
                    <div style="height: 35px; background-color: grey;">
                        <p style="font-size: 22px; font-weight: bold">@item.group_category</p>
                    </div>
                    <span class="helper">

                        <img src="~/images/@item.image_path" />

                    </span>
                </div>
                <div class="tabcolumn50">

                    <div style="height: 40px; border-bottom: 1px solid grey; border-left: 1px solid grey; border-right: 1px solid grey">
                        <p>&emsp;&emsp;&emsp;100kms per day&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.standard_100.00<br />(per day)"/>&emsp;Standard Cover&emsp;&emsp;&emsp;&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.super_100.00<br />(per day)" />&emsp;Upgrade to Super Cover</p>
                    </div>

                    <div style="height: 40px; border-bottom: 1px solid grey; border-left: 1px solid grey; border-right: 1px solid grey">
                        <p>&emsp;&emsp;&emsp;200kms per day&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.standard_200.00<br />(per day)" />&emsp;Standard Cover&emsp;&emsp;&emsp;&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.super_200.00<br />(per day)" />&emsp;Upgrade to Super Cover</p>
                    </div>

                    <div style="height: 40px; border-bottom: 1px solid grey; border-left: 1px solid grey; border-right: 1px solid grey">
                        <p>&emsp;&emsp;&emsp;400kms per day&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.standard_400.00<br />(per day)" />&emsp;Standard Cover&emsp;&emsp;&emsp;&emsp;&emsp;<input type="checkbox" class="slectOne" data-id="R @item.super_400.00<br />(per day)" />&emsp;Upgrade to Super Cover</p>
                    </div>

                    <div style="height: 55px; display: table; border-left: 1px solid grey; background-color: grey; width: 569px; border-right: 1px solid grey">

                    </div>
                    <input type="hidden" value="" id="rate" name="crate">
                </div>

                <div class="tabcolumn20" style="height: 160px">
                    <p style="font-size: 14px; text-align: center">Pick-up location: In Branch</p>
                    <p style="font-size: 14px; text-align: center">Fuel Policy: Full to Full</p>
                    <p id="currentRate" style="padding-left: 10px; padding-right: 10px; font-size: 18px; font-weight: bold; margin-top: 10px; text-align: center" class="result">Please choose cover to continue</p>

                    <input type="submit" onclick="getRate(); " value="Book Now!" style="height: 56px; background-color: yellow; width: 227.66px; border-style: none" />

                </div>
            </div>
            <br />
                }
            }
    </table>

    <script>
                        function getRate()
                        {
                            var cr = document.getElementById("currentRate").innerHTML;
                            var a = cr.substring(0, cr.length - 16);
                            var b = a.substring(2);

                            $.post("/Home/reservation_step_1  ", { x: b });
                        }
    </script>

    <script>
                        $(document).ready(function () {
                            $('.slectOne').on('change', function () {
                                $('.slectOne').not(this).prop('checked', false);

                                let result = $('.result', $(this).closest('.tabcolumn-container'));
                                result.html($(this).is(":checked") ? $(this).data("id") : '');
                            });
                        });
    </script>
</body>

它确实在HTML Helpers的帮助下工作(使用(Html.BeginForm(“ reservation_step_1”,“ Home”,FormMethod.Post))),但是随后使用ajax和html helpers传递数据同时使该动作循环两次并导致ajax值变为null。

关于如何保持ajax值传递给相应控制器并重定向到相应视图的任何帮助吗?

0 个答案:

没有答案