Click here to Skip to main content
15,356,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

    @foreach (var item in ((List
         )TempData["listesite"]).GroupBy(x => x.Nom))
            <th colspan="4"></th>
        foreach (var data in ((List<site>
      )TempData["listesite"]).Where(x => x.Nom == item.Key))


public ActionResult Index()
       TestEntities db = new TestEntities();
       TempData["listesite"] = db.Sites.ToList();
       return View();

What I have tried:

I want to display the data of the table according to the field Nom chosen on a combobox list.

For example, the combobox list contains Nom1, Nom2, Nom3.
If we choose on the list combobox Nom1

we must have only the records related to Nom1
Updated 4-May-22 6:12am
Mehul M Thakkar 9-Dec-19 9:48am
just show dropdown on top and bind with Unique Nom values.
On change of dropdown value make a server call and filter your list and show on UI.
Member 14663996 9-Dec-19 9:54am
new SelectList(Enumerable.Empty<site>(), "Code", "Nom"),
"Select Site",
new { @class = "form-control", id = "Lsite" })
F-ES Sitecore 9-Dec-19 9:57am
There are multiple ways of doing could re-submit the page when the drop-down changes causing all the work to be done back-end. You could make an ajax call when the drop-down changes, get the relevant data from that call and update the table client-side. Or you could get all the data in a js array and have the filtering done purely in javascript with no back-end work at all. Given you haven't said how you want this done it's hard to give specific code. I'm sure if you google "mvc filter data based on dropdown" you'll find many code samples across all possible methods.
Member 14663996 9-Dec-19 9:57am
I have to link the choice of the Nom on the list with the Nom on the table
Member 14663996 9-Dec-19 10:05am
Currently the code shows all the Noms. I want to display just the corresponding Nom at the combobox's choice.
I can do it directly on the view ?
Member 14663996 9-Dec-19 10:58am
public ActionResult GetNom(string nom)

if (!string.IsNullOrWhiteSpace(nom))
IEnumerable<site> listesites = Listesites.Where(listesite= => resultat.Nom == nom).ToList();
return Json(listesites, JsonRequestBehavior.AllowGet);
return null;
Member 14663996 9-Dec-19 11:04am
I want to use this function to sort the list before displaying it on java script code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900