San*_*eal 5 c# asp.net-mvc actionlink asp.net-mvc-4
我有一个简单的视图,如果登录成功并位于/ Login下,则会创建一个链接:
<div>
@Html.ActionLink("Add a new Organization", "AddOrganization",
"/Setup/AddOrganizationController", new { id = Session["ID"] }, null)
</div>
Run Code Online (Sandbox Code Playgroud)
在阅读其他类似的问题后,我尝试添加null之后,以及其他一些重载,但我无法使链接正常工作.当我点击链接时,它会带我去
http://setup/AddOrganizationController/AddOrganization
Run Code Online (Sandbox Code Playgroud)
哪个省略了需要在那里的localhost部分.最后没有null,它会尝试发送给我
/Login/AddOrganization
Run Code Online (Sandbox Code Playgroud)
我想要的只是一个链接,它将在AddOrganizationController控制器中运行一个动作,该控制器位于/ Setup目录下.该链接还应将会话ID作为参数传递给控制器.我怎样才能做到这一点?
如果它是相同的Area那么你可以这样做:
@Html.ActionLink("Add a new Organization", "AddOrganization", "Organizations", new { id = Session["ID"] })
Run Code Online (Sandbox Code Playgroud)
其中"组织"是控制器名称.
否则,如果它在另一个区域,你会做类似的事情
@Html.ActionLink("Add a new Organization", "AddOrganization", "Organizations", new { area = "areaName", id = Session["ID"] }, null)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19683 次 |
| 最近记录: |