我有以下ActionLink:
@if (ViewBag.Locality != null)
{
<h4>Active Localities:</h4>
<table class="table table-hover">
@foreach (var loc in ViewBag.Locality)
{
<tr>
<td>@loc.Locality</td>
<td>@Html.ActionLink(" ", "RemoveActive", new { @class = "removeBtn" }, new { id = @loc.Locality })</td>
</tr>
}
</table>
}
但是,类removeBtn
未在CSS中应用如下:
a.removeBtn
{
background:url('http://news.techgenie.com/files/symbols-delete.png') no-repeat top left;
display: block;
background-size: 20px;
width: 50px;
height: 20px;
text-indent: -9999px;
}
此外,在单击时,id未传递给控制器方法,该参数将作为null传递
答案 0 :(得分:1)
您正在以错误的方式使用actionlink,这是演示正确的actionlink用法:
Html.ActionLink(article.Title, <--Text of actionlink
"Item", <-- ActionMethod
"Login", <-- Controller Name.
new { article.ArticleID }, <-- Route arguments.
new { @class="btn" } <-- htmlArguments.
)
你的问题是:
@Html.ActionLink("// Title //", "RemoveActive", "// Your controller Name //" ,new { id = @loc.Locality },new { @class = "removeBtn" })