0
필자는 다음과 같이 약 보이는 사용자 정의 모델을 결합하려고 모든 필드 MVC4에 액세스 할 수 없습니다 바인딩 :사용자 정의 모델
내가 DIV 패널 다른 탐색 항목을 구분 더 나은 입력 양식 보이게하기 위해[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 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="[email protected]">
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에 양식에있는 라디오 단추 그룹에 대한 키가 없다는 것입니다. 내가 도대체 뭘 잘못하고있는 겁니까?
바인딩에 필요한 이름 속성을 설정하지 않았습니다. – Daniele
@ 대니얼 (Daniele), 답으로 게시하여 신용을 얻을 수 있습니다 :) – zmanc