我正在尝试使用MonoRail中的Checkboxlist来表示多对多的表关系。有一个Special table,SpecialTag表,然后是SpecialTagging表,它是Special和SpecialTag之间的多对多映射表。MonoRail CheckboxList?
下面是从特殊模型类的摘录:
[HasAndBelongsToMany(typeof(SpecialTag),
Table = "SpecialTagging", ColumnKey = "SpecialId", ColumnRef = "SpecialTagId")]
public IList<SpecialTag> Tags { get; set; }
然后在我的添加/编辑特别观点:
$Form.LabelFor("special.Tags", "Tags")<br/>
#set($items = $FormHelper.CreateCheckboxList("special.Tags", $specialTags))
#foreach($specialTag in $items)
$items.Item("$specialTag.Id") $Form.LabelFor("$specialTag.Id", $specialTag.Name)
#end
的CheckBoxList的正确渲染,但如果我选择一些,然后单击保存,它不会将特殊/标记关联保存到SpecialTagging表(传递给保存控制器操作的实体具有空的标记列表)。我注意到的一件事是复选框的名称和值属性很奇怪:
<label for="special_Tags">Tags</label><br>
<input id="3" name="special.Tags[0]" value="UCampus.Core.Models.SpecialTag" type="checkbox"> <label for="3">Buy 1 Get 1 Free</label>
<input id="1" name="special.Tags[1]" value="UCampus.Core.Models.SpecialTag" type="checkbox"> <label for="1">Free</label>
<input id="2" name="special.Tags[2]" value="UCampus.Core.Models.SpecialTag" type="checkbox"> <label for="2">Half Price</label>
<input id="5" name="special.Tags[3]" value="UCampus.Core.Models.SpecialTag" type="checkbox"> <label for="5">Live Music</label>
<input id="4" name="special.Tags[4]" value="UCampus.Core.Models.SpecialTag" type="checkbox"> <label for="4">Outdoor Seating</label>
任何人有任何想法?
谢谢! 贾斯汀