1、Model層定義屬性
public class vmUser { public string userName { get; set; } public string sex { get; set; } public int? age { get; set; } public DateTime? enrollDate { get; set; } public string deptName { get; set; } public Dictionary<string,bool> skills { get; set; } //鍵值對 public string email { get; set; } public string imgUrl { get; set; } }
2、View層控件展示
<p>擅長技能:@Html.CheckBoxFor(m => m.skills["體育"]) 體育 @Html.CheckBoxFor(m => m.skills["音樂"]) 音樂</p>
3、Action中獲取結果
Dictionary<string,bool> skills = user.skills;