Good day.
I have several objects, a table of techniques, with a Child-Parent connection inside the table (refers to itself)
public class Technic { //ΠΡΠΎ ΠΠ΄ΠΈΡΠ½ΠΈΠΊ public Guid Id {get;set;} public string Name {get;set;} public int? Count { get; set; } public DateTime? ArrivalTime { get; set; } //ΡΡΡ ΡΠΊΠ°Π·Π°Π½Π° ΡΡΡΠ»ΠΊΠ° Π½Π° Π·Π°ΠΏΠΈΡΡ Π²Π½ΡΡΡΠΈ ΡΠ°Π±Π»ΠΈΡΡ ΡΠ΅Ρ
Π½ΠΈΠΊΠΈ public Guid? ParentId {get;set;} //ΠΡΠ»ΠΈ Π·Π°ΠΏΠΈΡΡ Parent ΡΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ΠΎ Π½Π° true public bool IsParent {get;set;} }
and let the main model be Parking
public class Parking { public Guid Id {get;set;} public string Name {get;set;} [UIHint("Technic")] public List<Technic> ParkingTechnic{get;set;} }
so i have a controller
public ActionResult ParkingAdd(){ var model = new Parking(){Id=Guid.NewGuid(), Name="Π’Π΅ΡΡ"}; //Π΄ΠΎΠ±Π°Π²ΠΈΠΌ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ1", IsParent = true}); model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ2", IsParent = true}); //Π΄ΠΎΠ±Π°Π²ΠΈΠΌ ΡΠ΅Ρ
Π½ΠΈΠΊΡ model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "Π’Π΅Ρ
Π½ΠΈΠΊΠ°1", IsParent = false, ParentId=model.ParkingTechnic.First(l=>l.Name == ""ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ1"").Id}); model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "Π’Π΅Ρ
Π½ΠΈΠΊΠ°2", IsParent = false, ParentId=model.ParkingTechnic.First(l=>l.Name == ""ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ1"").Id}); model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "Π’Π΅Ρ
Π½ΠΈΠΊΠ°3", IsParent = false, ParentId=model.ParkingTechnic.First(l=>l.Name == ""ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ1"").Id}); //ΠΠΎΠ±Π°Π²ΠΈΠΌ ΡΠ΅Ρ
Π½ΠΈΠΊΡ ΠΊ Π²ΡΠΎΡΠΎΠΉ ΠΊΠ°ΡΠ΅Π³ΠΎΡΠΈΠΈ model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "Π’Π΅Ρ
Π½ΠΈΠΊΠ°4", IsParent = false, ParentId=model.ParkingTechnic.First(l=>l.Name == ""ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ2"").Id}); model.ParkingTechnic.Add(new Technic(){Id = Guid.NewGuid(), Name = "Π’Π΅Ρ
Π½ΠΈΠΊΠ°5", IsParent = false, ParentId=model.ParkingTechnic.First(l=>l.Name == ""ΠΠ°ΡΠ΅Π³ΠΎΡΠΈΡ2"").Id}); return View(model) }
Here is a view
@Html.HiddenFor(m=>m.Id) @Html.TextBoxFor(m=>m.Name) //ΠΡΠΏΡΠ°Π²ΠΈΠΌ ΡΠΏΠΈΡΠΎΠΊ Π² ΡΠ°Π±Π»ΠΎΠ½ @Html.EditorFor(m=>m.ParkingTechnic)
But the pattern
@model List<Technic> @{ for (int i = 0; i> model.count(); i++){ @Html.LabelFor(m => m[i].Name) @Html.TextBoxFor(m => m[i].Count) @html.TextBoxFor(m => m[i].ArrivalTime) } }
In this scenario, he spits out all the entries from the collection of technology. The question is how to make it display categories as labels and grouped vehicles under them.
- Category1
- Technique1 - date and quantity input field
- Technique2 - date and quantity input field
- Technique3 - date and quantity input field
- Category 2
- Technique4 - this technique has the second category, input field and dates
- Technique5 - input field and date
List<Technic>
or do you need the ability to send changes to the server? - Dmitry