Note that there are some explanatory texts on larger screens.

plurals
  1. POGeneric List Object OrderBy dynamic Column name
    primarykey
    data
    text
    <p>I am trying to sort data which is from <code>Generic List</code> object.<br> By using below code, I can sort my data according to <code>Title</code> column.<br> But what I would like to do is I would like to sort data according to parameter value called <code>sidx</code>.</p> <pre><code>public ActionResult ListingGridData(string sidx, string sord, int page, int rows) { int currentPage = Convert.ToInt32(page) - 1; int totalRecords = 0; var SeminarList = (List&lt;Seminar&gt;)null; if(sord.Equals("asc")) SeminarList = seminarRepository.AllSeminarList().Seminar_Masters .OrderBy(x =&gt; x.Title ) .Skip(currentPage * rows) .Take(rows) .ToList(); else SeminarList = seminarRepository.AllSeminarList().Seminar_Masters .OrderByDescending(x =&gt; x.Title) .Skip(currentPage * rows) .Take(rows) .ToList(); totalRecords = seminarRepository.AllSeminarList().Seminar_Masters.Count; var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); .... } </code></pre> <p>So I have modified my code like that, but it does not work.<br> It does not sort as I have expected.</p> <pre><code>SeminarList = seminarRepository.AllSeminarList().Seminar_Masters .OrderBy(x =&gt; sidx) .Skip(currentPage * rows) .Take(rows) .ToList(); </code></pre> <p>The object which I now use is pure <code>List</code> object, not <code>IQueryable</code> object. <br></p> <p>As for sorting purpose, I don't want to go back to <code>SQL select statement</code>, I would like to sort data at Controller layer.</p> <p>Please let me get any suggestions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload