5

我有一个简单的视图,如果登录成功,它会创建一个链接,并且位于 /Login 下:

<div>
@Html.ActionLink("Add a new Organization", "AddOrganization", 
           "/Setup/AddOrganizationController", new { id = Session["ID"] }, null)
</div>

在阅读了其他类似的问题之后,我尝试在之后添加 null 以及其他一些重载,但我无法让链接正常工作。当我点击链接时,它会带我到

http://setup/AddOrganizationController/AddOrganization

这忽略了需要存在的本地主机部分。最后没有空值,它会尝试将我发送到

/Login/AddOrganization

我想要的只是一个链接,它将在 /Setup 目录下的 AddOrganizationController 控制器中运行一个操作。该链接还应将会话 ID 作为参数传递给控制器​​。我怎样才能做到这一点?

4

1 回答 1

6

If it's in the same Area then you can just do:

@Html.ActionLink("Add a new Organization", "AddOrganization", "Organizations", new { id = Session["ID"] })

where "Organizations" is the controller name.

Otherwise, if it's in another area you would do something like

@Html.ActionLink("Add a new Organization", "AddOrganization", "Organizations", new { area = "areaName", id = Session["ID"] }, null)
于 2013-10-07T13:50:24.653 回答