简体   繁体   English

在MVC中,单击iis8.5托管应用程序的链接时URL不能正确显示

[英]In MVC url is not getting properly on clicking a link for the iis8.5 hosted application

I have a MVC4 application and have hosted on IIS8.5 with published file. 我有一个MVC4应用程序,并已在IIS8.5上托管了已发布的文件。 I have a link on my cshtml page 我的cshtml页面上有一个链接

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

Here home is controller and ContactGrabber is an action of controller. 这里home是控制器,而ContactGrabber是控制器的动作。 When I am clicking on this link it show 404 error because url is showing 当我单击此链接时,它显示404错误,因为URL正在显示

http://localhost/home/ContactGrabber

It should be 它应该是

http://localhost/cruuntest/home/ContactGrabber

But when I am running my development code without hosting on IIS. 但是,当我运行开发代码而不在IIS上托管时。 it works fine. 它工作正常。

Can anybody help me on this? 有人可以帮我吗?

Use Url.Action helper for this, so that your url is generated right, by this way you wull face issues: 为此,请使用Url.Action帮助程序,以便通过正确的方式生成您的网址,从而避免出现问题:

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

you can see details of it on MSDN 您可以在MSDN上查看它的详细信息

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

You can also use Html.ActionLink to generate the anchor tag: 您还可以使用Html.ActionLink生成锚标记:

Razor: 剃刀:

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

MSDN docs MSDN文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM