如何根据条件禁用列表项 - ASP.NET C#
Posted
技术标签:
【中文标题】如何根据条件禁用列表项 - ASP.NET C#【英文标题】:How to disable a list item based on condition - ASP.NET C# 【发布时间】:2018-10-27 10:48:53 【问题描述】:我正在寻找一些关于禁用两个列表项的最佳方法的建议,基于帐户被锁定并且状态列中的值等于 1。
我有一个生成随机数的模型:
public int IsLocked
get
var rnd = new Random();
return rnd.Next(0, 2);
这是我的局部视图:
<td class="hidden-xs hidden-sm">
@if (t.IsLocked == 1)
<span class="glyphicon glyphicon-lock locked"></span>
else
<span class="glyphicon glyphicon-ok"></span>
</td>
<td class="updateTableRow text-center">
<div class="dropdownContainer btn-group text-right">
<button id="@actionWorkId" type="button" class="btn btn-primary br2 btn-xs fs12 dropdown-toggle songmanagement-btn" data-toggle="dropdown" aria-expanded="false">
Action
<span class="caret ml5"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li>
<a href="@Url.Action("Recordings", "ArtistAccount", new
accountcode = fullAccountCode,
songcode = t.SongId
)" id="@recordingWorkId" data-container="body" data-rowhover="editTableRow" class="js_Recordings">Recordings</a>
</li>
<li>
<a href='@Url.Action("EditSong", "ArtistAccount", new
songcode = t.SongId,
accountcode = fullAccountCode,
page = Model.PagingInfo.Page,
take = Model.PagingInfo.Take,
sortBy = Model.PagingInfo.SortPropertyName,
sortAsc = Model.PagingInfo.SortAscending
)' id="@editWorkId" data-container="body" data-rowhover="editTableRow" class="js_EditSong">Edit</a>
</li>
<li>
<a href="#" id="@deleteWorkId" data-container="body" data-toggle="tooltip" title="Delete" data-rowhover="deleteTableRow" class="js_DeleteSong">Delete</a>
</li>
<li>
<a href="@Url.Action("TuneCodes", "ArtistAccount", new
accountCode = fullAccountCode,
workCode = t.SongId,
)" id="@tuneCodeId" data-container="body" data-toggle="tooltip" title="Tune Codes" data-rowhover="editTableRow">Tune Codes</a>
</li>
</ul>
</div>
</td>
</tr>
有没有使用 C# 和 ASP.NET 的方法可以实现这一目标?
【问题讨论】:
我不确定你在这里问什么。您是否正在寻找一种方法来查看您的编辑和录制 - 是否应该根据 t 启用链接? 那我觉得你的做法还不错! @sander 不会是动态的,但如果我只是将 disabled 属性添加到 html 【参考方案1】:使用以下代码解决了我的问题:
<li>
@if (t.IsLocked == 1)
<a class="isDisabled" data-toggle="tooltip" title="You cannot edit this song until pending writer edits are approved">Recordings</a>
else
<a href="@Url.Action("Recordings", "ArtistAccount", new
accountcode = fullAccountCode,
songcode = t.SongId
)" id="@recordingWorkId" data-container="body" data-rowhover="editTableRow" class="js_Recordings">Recordings</a>
</li>
<li>
@if (t.IsLocked == 1)
<a class="isDisabled" data-toggle="tooltip" title="You cannot edit this song until pending writer edits are approved">Edit</a>
else
<a href='@Url.Action("EditSong", "ArtistAccount", new
songcode = t.SongId,
accountcode = fullAccountCode,
page = Model.PagingInfo.Page,
take = Model.PagingInfo.Take,
sortBy = Model.PagingInfo.SortPropertyName,
sortAsc = Model.PagingInfo.SortAscending
)'
id="@editWorkId" data-container="body" data-rowhover="editTableRow" class="disabled">Edit</a>
【讨论】:
以上是关于如何根据条件禁用列表项 - ASP.NET C#的主要内容,如果未能解决你的问题,请参考以下文章
禁用菜单项时,如何将 VS Profiler 2012 附加到 ASP.NET 解决方案?