I have a dropdown, above a table, when you select the dropdown the selection is not pre-appending the selection. When I click the dropdown then click my table headers to sort them the dropdown selection is lost.
Dropdown
@Html.DropDownList("TenantList", (IEnumerable<SelectListItem>)ViewBag.TenantList, new { id = "ddlSociety", @class = "form-control" })
Table
<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>
Controller
/// <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;
});
});
Is there a way I can get it to pre-appending the selection, whilst the sorting on the table header is clicked? I am not sure if it is a JQuery issue?