간단한 양식으로 일부 데이터를 보내려고합니다. 내 양식에는 체크 박스 목록과 각 상자 옆에 사람의 이름과 역할이 있습니다. 내가하고 싶은 일 : 상자가 체크 된 사람의 목록을 복구하십시오. 나는 방법이 할 수있는 모델을 만들었습니다MVC 면도날 형식 : 데이터가 전송되지 않았습니다.
내 양식은 다음과 같습니다public class CoupleModel
{
public Boolean isSelected { get; set; }
public String name {get; set;}
public String login { get; set; }
public String role { get; set; }
public CoupleModel(String name, String login, String role)
{
this.name = name;
this.login = login;
this.role = role;
this.isSelected = false;
}
public CoupleModel()
{
this.isSelected = false;
}
}
:
@using (Html.BeginForm("CreateInventory", "Home"))
{
@Html.Action("PersonListInventory")
<button type="submit" class="btn btn-primary">Validate creation</button>
}
그리고 연결된 PartialView이 하나입니다
@model List<MyApp.Models.CoupleModel>
<table class="table table-striped table-bordered"">
<tbody>
@for (int i = 0; i < Model.Count(); i++) {
<tr>
<td>
@Html.EditorFor(m => m[i].isSelected)
</td>
<td>
@Html.EditorFor(m => m[i].name)
</td>
<td>
@Html.EditorFor(m => m[i].role)
</td>
</tr>
}
</tbody>
</table>
그리고 내 컨트롤러보기에서, 상자가 점검 된 사람들의 이름을 나열하기 만하면됩니다.
[HttpPost]
public ActionResult CreateInventory(List<CoupleModel> model)
{
String res = "";
foreach (var item in model) {
if (item.isSelected)
{
res += "selected : " + item.login + "<br>";
}
else
{
res += item.login + "<br>";
}
}
ViewBag.Res = res;
return View();
}
"isSelected"부분 만 설정됩니다. 즉, 표시 할 때 로그인이 항상 비어 있다고 가정합니다. 그것은 왜 설정되지 않았습니까? 특정 바인딩을 수행해야합니까?