当MVC项目被上传到Web服务器断开的链接 [英] Broken links when MVC project is uploaded to the WebServer

查看:118
本文介绍了当MVC项目被上传到Web服务器断开的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC项目,我出版了他与我的IIS Web服务器

I have a MVC project and I publish him in my Web Server with IIS

但一些按钮,我有以下的code

but some button, I have the following code

的JavaScript

$("#btn").click(function () {
   window.location.href = "/Home/Login";
});

这只是一个样本。

当我在点击链接时,将触发我的家庭控制器的登录方法。这本地主机工作正常。

When I click in my button, the Login method of my Home Controller is triggered. This works fine in localhost.

当我把这个项目中的服务器,我需要改变的href 把那里的应用程序都在的wwwroot

When I put the project in the server, I need change the href to put the folder name where the application are in wwwroot

$("#btn").click(function () {
   window.location.href = "/Web/Home/Login";
});

我如何prevent呢?
我有太多的图像和功能不使用中的wwwroot文件夹的名称。

How can I prevent this ? I have too many images and functions that don't use the folder name in wwwroot.

推荐答案

您可以在您的Razor视图写这个

You can write this in your razor view

<script type="text/javascript">
   var baseUrl = '@Url.Content("~")';
</script>

,你可以参考的baseUrl 在你的js code

and you can refer baseUrl in your js code

$("#btn").click(function () {
    window.location.href = baseUrl + "Home/Login";
});

的baseUrl 会给你的结果 /网络/ ,它应该引导你正确的路径调用。

The baseUrl will give you the result /Web/ and it should direct your call to the correct path.

这篇关于当MVC项目被上传到Web服务器断开的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆