1

我有一个 MVC4 应用程序,并已发布文件托管在 IIS8.5 上。我的 cshtml 页面上有一个链接

<a href='/home/ContactGrabber'>Import Contacts</a>

这里的 home 是控制器,而 ContactGrabber 是控制器的一个动作。当我单击此链接时,它显示 404 错误,因为 url 正在显示

http://localhost/home/ContactGrabber

它应该是

http://localhost/cruuntest/home/ContactGrabber

但是当我在没有托管在 IIS 上的情况下运行我的开发代码时。它工作正常。

有人可以帮我吗?

4

1 回答 1

2

为此使用Url.Action帮助程序,以便正确生成您的网址,这样您将面临问题:

<a href='@Url.Action("ContactGrabber","home")'>Import Contacts</a>

你可以在MSDN上查看它的详细信息

http://msdn.microsoft.com/en-us/library/dd505232%28v=vs.118%29.aspx

您还可以使用Html.ActionLink生成锚标记:

剃刀:

Html.ActionLink("Import Contacts", 
                "ContactGrabber",   // <-- ActionMethod
                "home",  // <-- Controller Name.
                 null, // <-- Route arguments.
                 null  // <-- htmlArguments .. which are none.
                )

MSDN 文档

于 2014-06-26T16:45:35.773 回答