我需要一些帮助 如果我的任务状态为true,我想禁用编辑和删除按钮 这是我的编辑和删除按钮视图
<td><a href = "@Url.Action("Edit","Task", new {id = task.TaskId})" class= "btn mini purple"><i class = "icon-edit"></i> Edit </a></td>
<td><a href = "@Url.Action("Delete","Task", new {id = task.TaskId})" class= "btn mini black"><i class = "icon-remove"></i> Delete </a></td>
答案 0 :(得分:0)
那些不是按钮。这些是HTML anchor elements。不能仅在HTML中禁用锚点元素。
看起来你正在使用旧版本的Bootstrap,但你没有在你的问题中包含这个。如果要添加disabled
类,可以这样做:
<td><a href = "@Url.Action("Edit","Task", new {id = task.TaskId})"
class= "btn mini purple @Disabled(task.Status)">
<i class = "icon-edit"></i> Edit </a></td>
<td><a href = "@Url.Action("Delete","Task", new {id = task.TaskId})"
class= "btn mini black @Disabled(task.Status)">
<i class = "icon-remove"></i> Delete </a></td>
@helper Disabled(bool disable)
{
if (disable)
{
@:disabled
}
}
答案 1 :(得分:0)
<a>
标记。因此,如果status为false,您可以删除它或阻止单击:
@if(yourStatus.IsOk)
{
<td><a href = "@Url.Action("Edit","Task", new {id = task.TaskId})" class= "btn mini purple"><i class = "icon-edit"></i> Edit </a></td>
<td><a href = "@Url.Action("Delete","Task", new {id = task.TaskId})" class= "btn mini black"><i class = "icon-remove"></i> Delete </a></td>
}
else
{
<td><a href="/" onclick="return false;" class= "btn mini purple"><i class = "icon-edit"></i> Edit </a></td>
<td><a href="/" onclick="return false;" class= "btn mini black"><i class = "icon-remove"></i> Delete </a></td>
}