【问题标题】:URL redirection using javascript in an MVC3 application在 MVC3 应用程序中使用 javascript 进行 URL 重定向
【发布时间】:2012-03-07 05:11:41
【问题描述】:
   @{
        var host = Url.Content("~/");
    } 


<script type="text/javascript">
    var host = "@host";
    $(function () {

        if ($("#Company" != null)) {
            $("#companyselect").change(function () {

                var newuri = host + "eg/" + $("#companyselect option:selected").text() + "/Comps";
                window.location.url = newuri;
            }
            );
        }
    });
</script>  

newuri = /bo/eg/airline inc/5

但是浏览器总是重定向到/eg/airline inc/5

【问题讨论】:

    标签: jquery asp.net-mvc-3 url redirect


    【解决方案1】:

    可能是您缺少主机名吗?在您当前的设置中,主机名的计算结果似乎只是“/”;

    例如,您可以尝试:

    var host = window.location.hostname;
    var newuri = host + "/eg/" + $("#companyselect option:selected").text() + "/Comps";
    window.location.url = newuri;
    

    【讨论】:

    • 不。它甚至比这更愚蠢。我有一个 $(function) 定义隐藏在页面正在加载的部分中。最终结果是它用旧路径覆盖了 newuri。
    猜你喜欢
    • 2015-12-28
    • 2011-11-13
    • 2021-08-07
    • 1970-01-01
    • 2015-10-26
    • 2018-09-05
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多