Is it possible to change display order of divs when rendering View Page on Server Side? Every single div has different c# and html content, so it's not possible to generate them by loop.
One option is display as is and reordering in client side when page OnReady by jQuery. But it has some delay time to rearrange divs.
Another option is generate view page for every div, then loop div ids, render content with @Html.Action
or @Html.RenderPartial
. It is not feasible when items are >20 and pages are >100
Any solution on server side would be appreciated.
Foo.cshtml page:
<div class="container">
<div id="a">
//some c# codes to render html
</div>
<div id="b">
//some other c# codes to render html
</div>
<div id="c">
//some another c# codes to render html
</div>
</div>
When Cookie value for ViewOrder: c,b,a
Expected output:
<div class="container">
<div id="c">
//some another c# codes to render html
</div>
<div id="b">
//some other c# code to render html
</div>
<div id="a">
//some c# codes to render html
</div>
</div>
Possible solution on client side with jQuery
$.fn.orderChildren = function(order) {
this.each(function() {
var el = $(this);
for(var i = order.length; i >= 0; i--) {
el.prepend(el.children(order[i]));
}
});
return this;
};
$(".user").orderChildren(["c","b","a"]);