c# - DataTables multisort columns .net mvc hint -


I am using the Datatables Jquery extension and I've done multicol sorting to read those posts:

My question is, those two methods depend on the model that I am using in my controller, in this situation

If I need to use the same code in other controllers, then I can repeat it and change the model field and the other And requires, for example.

It does not seem very dry to me.

How to proceed? Is the controller a good condition for those two methods?

  Private IOrderedQueryable & lt; Users & gt; CreateSortedQuery (DataTableParameterModel parameterModel, IQueryable & lt; User & gt; Basic) {var of ordered = (IOrderedQueryable & lt; user & gt;) Basic; (Int i = 0; i & lt; parameter model. ISortingCols; ++ i) {var ascending = string.Equals ("asc", parameterModel.SoSortDir [i], string compiler, ORDINAL IGNOR SEAS); Int sortCol = parameterModel. ISortCol [i]; Expression & lt; Funk & lt; User, string & gt; & Gt; Order = Express = gate ordering sort (sorting); If (ordering! = Null) {if (ascending) {obedved = (i == 0)? to be ordered. Orderbie (orderbay expedition): ordered CT.ThenBy (orderByExpression); } And {obediently = (i == 0)? Order code.OrderByDescending (orderByExpression): orderQuery.ThenByDescending (orderByExpression); }} And {if (ascending) {obedved = (i == 0)? to be ordered. OrderBe (C => ID.): Ordered CT.byBy (c => c.Id); } And {obediently = (i == 0)? Order ordered code.OrderByDescending (c => c.Id): ordered CT.ThenByDescending (orderByExpression); }}} Returned the ordered order; } Private expression & lt; Func & lt; User, string & gt; & Gt; GetOrderingFunc (Int ColumnIndex) {expression & lt; Func & lt; User, string & gt; & Gt; InitialorderingFunction; Switch (Column Index) {Case 1: Initial Format Tasks = C = & gt; C.firstName; break; Case 2: Initial Formatting = C = & gt; C.LastName; break; Case 3: Initial Format Tasks = C = & gt; C.UserName; break; Case 4: Initial Formatting = C = & gt; C.email; break; Case 5: Initial Formatting = C = & gt; C.BusinessName; break; Default: Initial Formatting = Zero; break; } Return InitialorderingFunction; }   

I think your question is close to these two answers:

:

  Public Static RootAequality GetInfo & lt; T, P & gt; (This HtmlHelper html, expression & lt; funk & lt; T, P & gt; & gt; action) where T: class {var expression = action.Body; String Field Name = Expression .mail; Name;  

and

with the LINQ dynamic query library:

  var results = data. where (/ * ... * /) . Choose (/ * ... * /). Orderbie (field-name + "acc");  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -