简体   繁体   中英

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. I have a link on my cshtml page

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

Here home is controller and ContactGrabber is an action of controller. When I am clicking on this link it show 404 error because url is showing

http://localhost/home/ContactGrabber

It should be

http://localhost/cruuntest/home/ContactGrabber

But when I am running my development code without hosting on 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:

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

you can see details of it on MSDN

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

You can also use Html.ActionLink to generate the anchor tag:

Razor:

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

MSDN docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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