BOSS
BOSS

Reputation: 1898

C# ASP MVC : navigate between different controllers views from HTML

I have a problem navigating between different controllers views from HTML

Like for example i have two controllers (User and Transaction)

and in my HTML there is a main menu where it has all the main navigations.

so if i wanna navigate to the User list my view would be "User/List_Users"

and if i am inside the Transaction view

(......com/Transaction)

if i clicked on User List it will navigate to

(......com/Transaction/User/List_Users)

instead of going to

(......com/User/List_Users)

So i tried using The Html Action like like

<li>@Html.ActionLink("User List","User/List_Users")</li>

but didn't do any good :(

Upvotes: 0

Views: 3848

Answers (3)

atbebtg
atbebtg

Reputation: 4083

I usually use the following

@Html.ActionLink("Link Text", "Action", "Controller", new { querystringparameter = querystringvalue }, null)

In your case it will be:

@Html.ActionLink("User List", "List_Users", "User", new { querystringparameter = querystringvalue }, null)

Upvotes: 2

Egor4eg
Egor4eg

Reputation: 2708

Use the overload which accepts controller name:

@Html.ActionLink("User List","List_Users", "User");

Upvotes: 2

JasCav
JasCav

Reputation: 34632

<li>@Html.ActionLink("Link Name", "Action")</li>

This is your basic ActionLink. An action is the specific method in the controller (which ultimately serves up a view).

If you need to link to a different controller (you need to link to a Transaction view from a User view, for example), you can do:

<li>@Html.ActionLink("Link Name", "Action", "Controller")</li>

Upvotes: 3

Related Questions