Reputation: 479
I have field name "GroupTitle" assigned to each Control. I want to loop through each element of Control assigned to particular group.
public class Groups
{
public virtual int Id { get; set; }
public virtual string GroupTitle { get; set; }
}
public class Controls
{
public int Id { get; set; } //Id
public string Name { get; set; } //name of control/element
public string ControlType { get; set; } // checkbox, radio button, textbox, time, date
public string Caption { get; set; } //caption/title/label
public string Content { get; set; } //in case of checkbox
public bool Mandatory { get; set; } //is mandatory to select or enter its value.
public string GroupTitle { get; set; } // there will be title at the top of controls if grouped together
//public List<SelectListItem> SelectOptions { get; set; } //select/dropdown options e.g. Pakistan, Uk for country dropdown
}
Below is my code . I am not sure how to access Model variable inside nested loop. This gives me error. Also it gives me error that Where clause does not exists.
@foreach (var groups in Model.Groups)
{
foreach (var row in Model.Controls.Where("GroupTitle ==", @groups.GroupTitle;))
{
}
}
Upvotes: 0
Views: 113
Reputation: 2421
Prove this:
@foreach (var groups in Model.Groups)
{
foreach (var row in Model.Controls.ToList().Where(x => x.GroupTitle == groups.GroupTitle))
{
}
}
I think this answers probably also applies to your case.
Upvotes: 1