首页 > 解决方案 > 当我在表头 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 问题?

标签: c#jqueryasp.net-mvcrazor

解决方案


推荐阅读