直截了当我觉得找不到语法......
我有一个使用id属性的ActionLink,
<td style="padding-right:35px">@Html.ActionLink("Edit", "EditUser", new { @id = user.ID.ToString("N") }, new { @class = "btn yellow"})</td>
基本上我想将此更改为btn,但我不知道如何传递id参数,我认为它是这样的......
<button type="button" class="btn blue" id="user.ID.ToString("N")" onclick="location.href='ReferralTarget/EditUser'"><i class="icon-edit"> Edit</button>
其中ReferralTarget是我的控件,EditUser是我的actionResult .. 请注意,这是一个使用Razor2视图的ASP.NET MVC4应用程序......
答案 0 :(得分:2)
尝试这样的事情:
<button type="button" class="btn blue" onclick="location.href='@Url.Action("EditUser", "ReferralTarget", new { @id = user.ID }'"><i class="icon-edit"> Edit</button>
答案 1 :(得分:0)
如果您喜欢jquery路线,也可以这样做:
@functions
{
private string GetUserId()
{
//I'm not sure where you are getting user from, but if it's from the model,
//you would need to change this to something like @Model.something....
return user.ID;
}
}
<script type="text/javascript">
$(document).ready(function() {
$('#edit').click(function() {
location.href = "ReferralTarget/EditUser/" + "@GetUserId()";
});
});
</script>
<input type="button" id="edit" value="edit" />
答案 2 :(得分:0)
有一个简单的伎俩 -
使用jqueryUi和justdo $("#linkid").button()
,并根据需要设置样式