【发布时间】:2013-04-11 17:32:02
【问题描述】:
设置:
我正在使用Html.ActionLink 帮助器在PasswordReset 控制器区域Admin 中为我的操作创建标签Reset。
Html.ActionLink 调用(已编辑,但仍然没有乐趣):
对 Html.ActionLink 的调用在 foreach 循环中(html 简化):
foreach(var item in Model.Entities)
{
<p>
@Html.ActionLink("Reset Password",
"Reset",
"PasswordReset",
new {area="Admin",
userName=item.UserName,
email=item.Email,
roles=item.Roles},
null)
</p>
}
我的行动:
[HttpGet]
public virtual ActionResult Reset(string userName, string email, string roles)
{
if (string.IsNullOrEmpty(userName)) throw new ApplicationException("Invalid Username!");
var ue = new UsernameEmailDTO
{
UserName = userName,
Email = email,
Roles = roles
};
return View(ue);
}
路线:
context.MapRoute(
"Admin_PasswordReset",
"Admin/Password/Reset/{userName}",
new { controller = "PasswordReset", action="Reset", email = UrlParameter.Optional, roles = UrlParameter.Optional }
);
问题:
我可以直接使用路由调用动作。
但是,我的操作链接只生成一个指向当前页面的链接。
所以我的 Html.ActionLink 代码中一定有错误。
但是什么?!
非常沮丧,因为我以为我已经克服了这种疼痛障碍。
【问题讨论】:
-
从臀部射击,但尝试将控制器属性移出 routeValues 并移入 ActionLink 帮助器的本机参数。
-
@Moby'sStuntDouble:不,也不起作用。但是,我已根据您的建议修改了问题。
-
你能发布由 Html.ActionLink 生成的链接吗?
-
如问题所述,它只生成一个指向当前页面的链接。没有必要张贴。
-
只是想帮助你!可能是区域配置搞砸了!也许 Html.RouteLink 解决了这个问题。看看这里! stackoverflow.com/questions/5432185/…
标签: asp.net-mvc asp.net-mvc-4 html.actionlink