-1

I'm Kinda new to MVC.net,Still a student I'm trying to be better

here's what I have

@Html.ActionLink(item.nom_d, "index", "filières")

In each department there's many sub-departments so i want to know how can I filter this action-links so it'll show me only the sub-departments under the Item.nom_d only I hope I made it a little bit clear.

  • please reformulate your question and/or include some more code. What you are asking is related to behaviour that should be performed in a controller and what you are showing is just a Helper code from a View. Also, I recommend do some more research about MVC. – javier_el_bene May 16 '17 at 18:13
  • I'm sorry if it wasn't clear, i want to filter then next view ( filières ) according to item.nom_d , i did some searching but couldn't understand quiet well. if you still don't understand . i want to use some SQL Query to Dynamically change te Filière View .. thank you for your time – Hadjadj Achraf May 16 '17 at 19:11
  • Your problem seems to be conceptual. You can't "filter the ActionLink". The ActionLink is going to create a WebRequest which should be captured by a Controller method. Then in this context is where you can filter your data layer using the item.nom_d field and get the sub-departments. Having that, you can return a View or a PartialView with the sub-departments data. That's an abstracted idea of the workflow you should follow and the more that I can help you without code. – javier_el_bene May 16 '17 at 19:19
  • so want to say that i should create a controller for each Item.nom_d ? – Hadjadj Achraf May 17 '17 at 12:05
  • No. The controller will be a GET request which is going to receive Item.nom_d as a parameter and is going to return a View or a PartialView with the subdepartments. Clear enough? – javier_el_bene May 17 '17 at 13:05
  • I'm sorry i know i bothered you , my view generates the list of Nom_d , how can i know which one the user clicked on to start the filter action – Hadjadj Achraf May 17 '17 at 19:40
  • No problem. Assuming that you have a list of departments then you don't have an ActionLink at all. Just use a control (DataGrid, DropdownList, etc) to show the list of departments and the event Click or Select of the control will provide the id and also will allow you call the controller directly. Here are some grids options: http://stackoverflow.com/questions/14079003/asp-net-mvc-4-datagrid – javier_el_bene May 17 '17 at 19:49
  • i found a solution , thank you sir here's what i did the action link in département view " @Html.ActionLink(item.nom_d, "index", "filieres", new { ModelID = item.nom_d },null ) " & the index controller of filieres " public ActionResult Index(string modelID) { filiere F = new filiere(); List filieres = db.filiere.Where(filiere => filiere.nom_d == modelID).ToList(); return View(filieres); " – Hadjadj Achraf May 18 '17 at 22:12

2 Answers2

0

Are you looking for a DropdownList? Because if I look at your code, it seems like you would like to change the text of your Html.ActionLink?

pieter-jan
  • 11
  • 4
0

i found a solution , thank you sir here's what i did the action link in département view " @Html.ActionLink(item.nom_d, "index", "filieres", new { ModelID = item.nom_d },null ) " & the index controller of filieres "

 public ActionResult Index(string modelID)
            {
                filiere F = new filiere();
                List<filiere> filieres = db.filiere.Where(filiere => filiere.nom_d == modelID).ToList();                 


                return View(filieres); 

"