M Zeinstra
M Zeinstra

Reputation: 1981

Routing in MVC doesn't always work correct

My problem is as simple as the title.

I want to link to an action from a controller, but doesn't always work. I know what the problem is, but don't know how to solve it.

Imagine you're at the home page, the URL is then something like this: localhost:1234/. When I use the following URL in a link (<a>-tag) to go to the action configure, the href in that link-tag will then look like this: configure. But this doesn't work because it will send the user to localhost:1234/configure. Instead of this it should be localhost:1234/device/configure where device is the controller.

I could change the href in the link-tag to device/configure, but then it wouldn't work anymore when the user is redirected to the homepage. Because the url of the homepage is then localhost:1234/device/view (the default route, configured in RouteConfig.cs) and the link will send the user to localhost:1234/device/device/configure

I've already tried to use @Url.Action and @Html.ActionLink, but that doesn't work either.

Does anyone know how to make sure it will always send the user to the right URL?

Here is my RouteConfig if you need it.

Upvotes: 1

Views: 76

Answers (1)

AnotherGeek
AnotherGeek

Reputation: 884

Try this:

@Html.ActionLink("link text", "configure", "device")

Upvotes: 2

Related Questions