How do I make the selected item in a Categories List reallocate in the first position

0

In my application I have an area with several category links that is a PartialView.

The following categories come from the following Categories of ControlController

var categorias = db.Categorias.ToList();

Shoes | Health and Beauty | Supermarkets | Restaurants

The ActionResult of the encoded PartialView below knows which link the user clicked through a TempData ("SelectedSelect") .

[AllowAnonymous]
public ActionResult _CatalogoFiltroCategoria()
{
    TempData.Keep("filtroSelecionado");

    var categorias = db.Categorias.ToList();

    return PartialView(@"~/Views/Anuncios/_CatalogoFiltroCategoria.cshtml", categorias);
}

How do I get the var categories to put the selected link as the first of the ToList ().

Click on Restaurants to return the list to me.

Restaurants | Shoes | Health and Beauty | Supermarkets

Click on Health and Beauty and return to the list with Health and Beauty at the top of the list

Health and Beauty | Shoes | Supermarkets | Restaurants

    
asked by anonymous 11.11.2018 / 15:58

1 answer

0

Using linq you can use the insert command by passing the index and the item. Example:

Given your list Health and Beauty | Shoes | Supermarkets | The Imagine if you want to put shoes on first, you would do the following:

categorias.RemoveAt(1);
categorias.Insert(0,"Calçados");

What would make it look like this:

Shoes | Health and Beauty | Supermarkets | Restaurants

    
11.11.2018 / 16:44