Vikas

Vikas

  • NA
  • 831
  • 196k

Desc Order List In Dropdownlist Using .Net Core With MVC 5

Jul 13 2019 2:30 AM
I have 1 dropdownlist, In this dropdown list value is shown like Season 1, Season 2, .... Season10.
I want to display my list descending order like Season 10 , Season 9 and so on.
Here is my dropdownlist Code:-
 
 My Controller:-
  1. public static async Task> GetSeasonList()      
  2.         {      
  3.             IEnumerable _objSeasons = null;      
  4.             using (var _seasonsList = new HttpClient())      
  5.             {      
  6.                 _seasonsList.BaseAddress = new Uri("http://localhost:59745/api/");      
  7.                 _seasonsList.DefaultRequestHeaders.Clear();      
  8.                 _seasonsList.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));      
  9.                 HttpResponseMessage seasons = await _seasonsList.GetAsync("SeasonLists");      
  10.                 if (seasons.IsSuccessStatusCode == true)      
  11.                 {      
  12.                     _objSeasons = seasons.Content.ReadAsAsync>().Result;      
  13.                 }      
  14.             }      
  15.             return _objSeasons ;      
  16.         }      
 
 cshtml page:-
  1. <select id="dropdownSessionId" class="selectActive" name="seasonlist">  
  2.         <option disabled selected>Select Season<option>  
  3.         @foreach (var seasonslist in @Model.Seasons)  
  4.             {  
  5.                    <option onchange="@Seasons.SessionId">@seasonslist.seasonName<option>  
  6.             }  
  7. </section>

Answers (2)