我有分配給每個控件的字段名稱「GroupTitle」。我想遍歷每個分配給特定組的控制元素。在剃刀內循環
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
}
以下是我的代碼。我不知道如何訪問嵌套循環內的模型變量。這給了我錯誤。它也給我錯誤,Where子句不存在。
@foreach (var groups in Model.Groups)
{
foreach (var row in Model.Controls.Where("GroupTitle ==", @groups.GroupTitle;))
{
}
}
你能向我們解釋一下你想達到的目標嗎? – Marco 2014-09-23 07:20:44
請參閱我的修改後的帖子。 – 2014-09-23 07:27:06
我認爲你的意思是'foreach(var在Model.Controls.Where(r => r.GroupTitle == groups.GroupTitle));' – 2014-09-23 07:28:13