사용자 지정 모델을 바인딩하려고합니다. 대략 다음과 같습니다.
[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>
}
문제는 내가 Default DefaultModelBinder를 파생 할 때 controllerContext.HttpContext.Request.Form에 양식에있는 라디오 버튼 그룹에 대한 키가 포함되어 있지 않다는 것입니다. 내가 무엇을 잘못하고 있지?
바인딩에 필요한 이름 속성을 설정하지 않았습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다