おおよそ次のようなカスタム モデルをバインドしようとしています。
[ReadOnly(true)]
[DisplayName("User ID")]
public String ID { get; set; }
[DisplayName("User Name")]
[Required]
public String Name { get; set; }
[DisplayName("Change Password")]
[Required]
public bool ChangePassword { get; set; }
[DisplayName("New password")]
[Required]
public String NewPassword { get; set; }
public Dictionary<String,Dictionary<String,bool>> Navigation { get; set; }
入力フォームの見栄えを良くするために、さまざまなナビゲーション項目を div パネルで分離します。
<div class="row">
<div class=".small-12.large-3.large-centered.columns">
<h2>EditUser</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.Partial("ValidationSummary", @ViewData.ModelState)
<div>
<legend>User details</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.NewPassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.NewPassword)
@Html.ValidationMessageFor(model => model.NewPassword)
</div>
<div class="editor-field">
<div class="switch">
<input id="switch-off" type="radio" name="switch-x" checked />
<label for="switch-off">Keep</label>
<input id="switch-on" type="radio" name="switch-x" />
<label for="switch-on" id="offClick">Change</label>
<span></span>
</div>
</div>
@{
int m = 0;
}
@{int k = 0;}
@foreach (var item in Model.Navigation)
{
<div class="panel">
@{String name = names.Keys.ToArray()[m];}
<h3>@name</h3>
<div class="editor-field">
@for (int i = 0; i < item.Value.Count; i += 3)
{
@:<div id="btnset_@k">
for (int j = 0; j < 3; j++)
{
if (i + j < item.Value.Count)
{
String id = item.Key + "_" + item.Value.Keys.ToArray()[i + j];
String value = item.Value.Values.ToArray()[i + j] ? "checked=\"checked\"" : String.Empty;
<input type="checkbox" id="@id" @value />
<label for="@id">@names[name][i + j]</label>
}
}
@:</div>
k++;
}
</div>
</div>
m++;
}
<p>
<input type="submit" value="Save" class="button" />
</p>
</div>
}
問題は、デフォルトの DefaultModelBinder を派生させるときに、controllerContext.HttpContext.Request.Form に、フォームにあるラジオ ボタン グループのキーが含まれていないことです。私は何を間違っていますか?