Stan
Stan

Reputation: 73

How can I call a controller from other folder with ActionLink

I have 2 controllers in different folders. /Areas/Admin/Controllers/ and the other one is in /Controllers.

Here's the code I'm using @Html.ActionLink("Back", "Directory", "DirectoryWebService", new { ReturnUrl = Model.ReturnUrl }, new { @class = "common-button" })

Using the code from Views/Directories/filename.cshtml works fine and generates the correct link "/DirectoryWebService/Directory?returnUrl=/Default/Traceability" DirectoryWebService is in /Controllers folder

However, using this code from /Areas/Admin/Views/Organizations/Index.cshtml generates the following link "/Admin/DirectoryWebService/Directory ReturnUrl=%2FDirectoryWebService%2FDirectory%3FreturnUrl%3D%2FDefault%2FTraceability" Controller for Index.cshtml is in /Areas/Admin/Controllers/ folder

The question is how can I avoid /admin in the path for the second case? I haven't mentioned in my code. PS I know about the a tag solution. It works fine but I need actionLink here.

Upvotes: 0

Views: 140

Answers (1)

SNBS
SNBS

Reputation: 849

You may remove the area variable from route.

@Html.ActionLink("Back", "Directory", "DirectoryWebService", new {
  area = "",
  returnUrl = Model.ReturnUrl
}, new {
  @class = "common-button"
});

Upvotes: 1

Related Questions