我有一个生成随机数的模型:
public int IsLocked
{
get
{
var rnd = new Random();
return rnd.Next(0, 2);
}
}
这是我的局部视图:
<table class="table table-striped table-hover dataTable admin-form theme-primary songsTable" cellspacing="0" width="100%" role="grid">
<thead id="tableHeader">
<tr>
<th class="bg-white text-left hidden-xs">
Song ID
</th>
<th class="sorting text-left @Html.SortTitleItem("Title", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
<a href="@Url.Action("SongManagement", "ArtistAccount", new
{
page = 1,
take = Model.PagingInfo.Take,
sortBy = "Title",
sortAsc = Model.PagingInfo.SortPropertyName != "Title" || !Model.PagingInfo.SortAscending
})" data-container="body" data-toggle="tooltip" title="Sort by Song Title">Song Title</a>
</th>
<th class="sorting text-left hidden-xs hidden-sm @Html.SortTitleItem("CreatedDate", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
<a href="@Url.Action("SongManagement", "ArtistAccount", new
{
page = 1,
take = Model.PagingInfo.Take,
sortBy = "CreatedDate",
sortAsc = Model.PagingInfo.SortPropertyName != "CreatedDate" || !Model.PagingInfo.SortAscending
})" data-container="body" data-toggle="tooltip" title="Sort by Created Date">Created Date</a>
</th>
<th class="bg-white text-left hidden-xs hidden-sm">
Writers
</th>
<th class="bg-white text-left hidden-xs hidden-sm">
Recordings
</th>
<th class="bg-white text-left hidden-xs hidden-sm">
State
</th>
<th class="bg-white text-left">
<div class="text-center">Action</div>
</th>
</tr>
</thead>
<tbody>
@foreach (var t in Model.Songs)
{
var actionWorkId = "actionWork_" + tableRowIndex;
var recordingWorkId = "recordingWork_" + tableRowIndex;
var editWorkId = "jsEditWork_" + tableRowIndex;
var deleteWorkId = "deleteWork_" + tableRowIndex;
var tuneCodeId = "tuneCode_" + tableRowIndex;
var writerShares = string.Join("<br />", t.Writers.Select(w => w.IsUnknown ? "UNKNOWN: " + string.Format("{0:0.00}", w.Share) + "%"
: w.Name + ": " + string.Format("{0:0.00}", w.Share) + "%"));
<tr data-id="@t.ID"
data-rowversion="@t.RowVersion">
<td class="hidden-xs">
@t.SongId
</td>
<td>
@t.Title
</td>
<td class="hidden-xs hidden-sm">
@t.CreatedDate
</td>
<td class="hidden-xs hidden-sm">
<span class="label label-rounded label-primary" data-container="body" data-toggle="tooltip" data-html="true" title="@writerShares">@t.Writers.Count()</span>
</td>
<td class="hidden-xs hidden-sm">
<span class="label label-rounded label-default">@t.Recordings</span>
</td>
<td class="hidden-xs hidden-sm">
<span class="glyphicon glyphicon-lock">@t.IsLocked</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" data-toggle="dropdown" aria-expanded="false">
Action
<span class="caret ml5"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li class="disabled">
<a href="@Url.Action("Recordings", "ArtistAccount", new
{
accountcode = fullAccountCode,
songcode = t.SongId
})" id="@recordingWorkId" data-container="body" data-toggle="tooltip" title="You cannot edit this song until pending writer edits are approved" data-rowhover="editTableRow" class="js_Recordings">Recordings</a>
</li>
<li class="disabled">
<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-toggle="tooltip" data-rowhover="editTableRow" class="disabled" title="You cannot edit this song until pending writer edits are approved">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>
tableRowIndex++;
}
</tbody>
</table>
@Html.Partial("_Pagination", Model.PagingInfo)
</div>
我可以生成随机数,但是有一种方法可以显示如果数字为1则为<span class="glyphicon glyphicon-lock">
的锁,如果数字为零则为<span class="glyphicons glyphicons-unlock"></span>
的锁。
我当时正在考虑在JQuery中做某事,但是如果有人有另一种方法那就太好了。
参考方案
您可以使用Razor做一个简单的if / else,就像这样:
@if (t.IsLocked == 1)
{
<span class="glyphicon glyphicon-lock"></span>
} else {
<span class="glyphicons glyphicons-unlock"></span>
}
ASP.NET-如何更改JSON序列化的方式? - javascript我正在使用ASP.NET通过以下查询返回Json文件:public ActionResult getTransactionTotals(int itemID) { DBEntities db = new DBEntities(); var query = from trans in db.Transactions // Linq query removed …
ASP.net C#崩溃一行 - c#我有一个母版页,在on load事件中包含以下几行: string menuIDdata = Page.Request.QueryString["mid"]; menuID = 0; // Get the menu ID if (!int.TryParse(menuIDdata, out menuID)) { menuID = 0; } …
在JavaScript中运行方法C# - javascript打扰一下,我有这种C#asp方法。受保护的无效btnSave_Click(对象发送者,EventArgs e)有谁知道我该如何发送脚本给您?可以办到?。 javascript大神给出的解决方案 是的,那可以做到。为此,您在.aspx.cs页中创建了函数,然后单击保存按钮上的代码将其复制到函数中,然后执行以下步骤。//Call cs method from J…
jQuery PHP发布 - javascript我有一个问题,也许很简单,但是当我发送jquery_send.php的数据时,我不知道如何加载jquery_post.php我恢复了将信息从jquery_send.php发送到jquery_post.php并希望在发送页面jquery_post.php后加载与数据这是我在jquery_send.php中拥有的:<html> <head>…
.NET C#Webbrowser填充输入,不带ID或类名 - javascript我需要在网络浏览器中填写一个输入,但这不起作用。我认为必须使用name属性来完成,但是怎么做呢?foreach (HtmlElement login in webBrowser1.Document.GetElementsByTagName("input")) { if (login.GetAttribute("name"…