c# - 当我在表头 JQuery 上选择排序时,下拉选择不会预先附加
问题描述
我在表格上方有一个下拉列表,当您选择下拉列表时,选择不会预先附加选择。当我单击下拉菜单然后单击我的表头对它们进行排序时,下拉选择会丢失。
落下
@Html.DropDownList("TenantList", (IEnumerable<SelectListItem>)ViewBag.TenantList, new { id = "ddlSociety", @class = "form-control" })
桌子
<th class="sorting text-left hidden-xs hidden-sm @Html.SortTitleItem("SongId", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
<a href="@Url.Action("VerifiedSongs", "SongsManagement", new
{
songid = songId,
page = 1,
take = Model.PagingInfo.Take,
sortBy = "SongId",
sortAsc = Model.PagingInfo.SortPropertyName != "SongId" || !Model.PagingInfo.SortAscending
})" data-container="body" data-toggle="tooltip" title="Sort by Song ID">Song ID</a>
</th>
控制器
/// <summary>
/// Verified Songs
/// </summary>
/// <param name="uniqueworkid">The accountcode.</param>
/// <param name="page">The page.</param>
/// <param name="take">The take.</param>
/// <param name="sortBy">The sort by.</param>
/// <param name="sortAsc">if set to <c>true</c> [sort asc].</param>
/// <returns></returns>
[HttpGet]
[Route("VerifiedSongs")]
[AuthorizeTenancy(Roles = "super,administrator")]
public ActionResult VerifiedSongs(int page = 1, int take = Constants.MVC.Pagination.DefaultItemsPerPage,
string sortBy = "CreatedDate", bool sortAsc = true)
{
// init
ViewBag.TenantCatalogues = null;
var model = new ViewModels.VerifiedSongViewModel();
// Get the paging and sorting parameters from the model (if supplied), else use acceptable defaults.
var skip = (page * take) - take;
var songs = GetSongs(skip, take, sortBy, sortAsc);
var songsTotalCount = GetSongs(0, int.MaxValue, string.Empty, true).ToList().Count;
//var tenants = GetTenants(skip, take, sortBy, sortAsc);
model.PagingInfo = new ViewModels.PagingModel
{
Page = page,
Take = take,
SortAscending = sortAsc,
SortPropertyName = sortBy,
Total = songsTotalCount,
PipedFilter = string.Empty
};
model.Songs = songs;
//model.Tenants = tenants;
PopulateTenantsDropDownList();
// AJAX?
if (!Request.IsAjaxRequest())
{
return View(model);
}
return PartialView("_VerifiedSongsList", model);
}
/// <summary>
/// Get Verified Songs
/// </summary>
/// <param name="uniqueworkid">The accountcode.</param>
/// <param name="page">The page.</param>
/// <param name="take">The take.</param>
/// <param name="sortBy">The sort by.</param>
/// <param name="sortAsc">if set to <c>true</c> [sort asc].</param>
/// <returns></returns>
[HttpGet]
[Route("GetVerifiedSongs")]
[AuthorizeTenancy(Roles = "super,administrator")]
public ActionResult GetVerifiedSongs(string societyId, int page = 1, int take = Constants.MVC.Pagination.DefaultItemsPerPage,
string sortBy = "CreatedDate", bool sortAsc = true)
{
//var lookupId = int.Parse(societyId);
var skip = (page * take) - take;
//var lookupId = 1;
var model = GetSongs(skip, take, sortBy, sortAsc);
return PartialView("_VerifiedSongsList", model);
}
/// <summary>
/// Populate the Tenants/Society Dropdown list
/// </summary>
/// <param name="selectedTenant">Selected tenant - if submitted persist state of selection.</param>
/// <returns></returns>
private void PopulateTenantsDropDownList(object selectedTenant = null)
{
var tenants = GetTenants(0, int.MaxValue, string.Empty, true);
var tenantsQuery = from t in tenants
orderby t.Name
select new
{
Tenantname = t.Name + " - " + t.TenantGroupName + " - CAEIPI Number: " + t.CAEIPINumber,
TenantID = t.ID
};
ViewBag.TenantList = new SelectList(tenantsQuery, "TenantID", "Tenantname", selectedTenant);
}
private IEnumerable<VerifiedSongDataViewModel> GetSongs(int skip, int take, string fieldToSort = "SongTitle", bool ascending = true)
{
var songs = new List<ViewModels.VerifiedSongDataViewModel>
{
new ViewModels.VerifiedSongDataViewModel
{
ID = Guid.NewGuid(),
RowVersion = Guid.NewGuid(),
IsDeleted = false,
SongId = "SEN123456789S",
SongTitle = "SongTitle",
AccountUniqueCode ="SEN123456789A",
CatalogueUniqueCode = "SEN987654321C",
CreatedDate = DateTime.UtcNow
},
jQuery
@* Sorting Async Partial Handling *@
$(document).on("click",
"#tableHeader a",
function()
{
loadPartialPage($(this).attr("href"));
return false;
});
});
有没有办法让它预先附加选择,同时点击表格标题上的排序?我不确定这是否是 JQuery 问题?
解决方案
推荐阅读
- jenkins - 将文件从主机复制到从机
- android - 如何在sqlite数据库中插入动态edittext字段的值
- amazon-web-services - 在过去两个小时内检查 S3 存储桶是否有新文件
- azure - Azure DevOps - 在 ARM 模板参数中使用 ARM 输出
- javascript - FormData 构造函数在 Edge 中丢失 textarea 值
- java - 如何转换 Arraylist
>到数组列表 - c++ - 具有枚举方向/类型的冒泡排序结构数组
- python - 多范围部分的数学
- javascript - 打字稿/反应。错误类型'{键:数字;}' 不可分配给类型 ILink(SFC 组件)
- xslt-grouping - XSLT 不同的节点组合