我正在尝试使用@ Html.ActionLink并发送my @ Html.DropDownList所选项的值。
这是我的代码:
<span class="MemberList">
@Html.DropDownList("ParticipantList", new SelectList(ViewBag.ParticipantList, "UserName", "UserName", ViewBag.ParticipantList), new { @class = "members" })
</span>
<span>
@Html.ActionLink("Login", "Impersonate", "Studio", new { username = DropDown.SelectedValue }, new { @class = "gobutton3" })
</span>
所以我想知道如何将值发送到ActionLink
答案 0 :(得分:3)
向链接添加动态内容的唯一方法是通过脚本
<a class="lnkLogin" href="#">Login</a>
然后在你的脚本中
$('.lnkLogin').on('click', function(){
var url = '@Url.Action("Impersonate", "Studio", new { username = "----" })';
url = url.replace("----", $('#ParticipantList').val());
window.location = url;
});
这将使用window.location重定向。作为登录,您可能希望在重定向之前执行ajax调用以验证凭据。