在MVC3应用程序中使用javascript进行URL重定向

时间:2012-02-15 20:07:39

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

   @{
        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

1 个答案:

答案 0 :(得分:0)

可能是你错过了主机名吗?在您当前的设置中,主机名看起来只会评估为“/”;

例如,您可以尝试:

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