0
동적으로 테이블을 만들고 삭제하는 테이블이 있습니다. 행을 추가 및 삭제하고 그에 따라 모델 정보 속성을 채우도록 코드를 어떻게 변경할 수 있습니까?비 순차 배열의 모델 바인딩
행을 동적으로 생성하고 삭제할 수 있다는 것을 염두에두면 Info [0], Inf0 [3], info [4]가있을 수 있습니다 ... 내 목표는 배열 연속적이지 않다.
모델
public class Person
{
public int[] Size { get; set; }
public string[] Name { get; set; }
public Info[]info { get; set; }
}
public class Info
{
public string Address { get; set; }
public string Tel { get; set; }
보기
<script type="text/javascript" language="javascript">
$(function() {
var count = 1;
$('#AddSize').live('click', function() {
$("#divSize").append('</br><input type="text" id="Size" name="Size" value=""/><input type = "button" id="AddSize" value="Add"/>');
});
$('#AddName').live('click', function() {
$("#divName").append('</br><input type="text" id="Name" name="Name" value=""/><input type = "button" id="AddName" value="Add"/>');
});
$('#AddRow').live('click', function() {
$('#details').append('<tr><td>Address</td><td> <input type="text" name="Info[' + count + '].Address"/></td><td>Tel</td><td><input type="text" name="Info[' + count++ + '].Tel"/></td> <td><input type="button" id="AddRow" value="Add"/> </td></tr>');
});
});
</script>
</head>
<body>
<form id="closeForm" action="<%=Url.Action("Create",new{Action="Create"}) %>" method="post" enctype="multipart/form-data">
<div id="divSize">
<input type="text" name="Size" value=""/> <input type="button" value="Add" id="AddSize" />
</div>
<div id="divName">
<input type="text" name="Name" value=""/> <input type="button" value="Add" id="AddName" />
</div>
<div id="Tab">
<table id="details">
<tr><td>Address</td><td> <input type="text" name="Info[0].Address"/></td><td>Tel</td><td><input type="text" name="Info[0].Tel"/></td> <td><input type="button" id="AddRow" value="Add"/> </td></tr>
</table>
</div>
<input type="submit" value="Submit" />
</form>
</body>
}
컨트롤러
public ActionResult Create(Person person)
{
return new EmptyResult();
}