그래서 나는 IncomeDeclaration에 대한 복잡한 폼이 있습니다.jquery ajax 및 asp.net mvc 템플릿에 도움이
IncomeDeclaration과 관련된 각 활동에 대한 텍스트 필드 GrossIncome이 표시됩니다.이 모든 것은 서버에서 완료되며 정상적으로 작동합니다 .... 문제가 있습니다. 사용자는 또한 javascript를 통해 즉석에서 활동을 추가 할 수 있어야합니다 ... 사용자가 활동 추가 드롭 다운을 클릭하고 텍스트 필드를 활동 목록의 맨 아래에 추가해야 할 때 ... 지금까지 내가 가진 것
<tbody id="activities">
@Html.EditorFor(model => model.income.EconomicActivityIncomeDeclarations)
</tbody>
</table>
<a href="#" id="add_activity">Agregar Otra Actividad</a>
</fieldset>
<script type="text/javascript">
$("#add_activity").click(function() {
$.getJSON('/IncomeDeclarations/GetEconomicActivities', function (data) {
var select = new Select();
var data = new Array();
for (var i = 0; i < data.length; i++) {
var option = new Option(data[i]["name"], data[i]["i"])
//should do something here
}
//should call the template and append to #activities
});
});
</script>
<script id="template" type="text/x-jquery-tmpl">
<tr>
<td><select name="income.EconomicActivityIncomeDeclarations[${SomeNumber}].EconomicActivityId">
${MyOptions}
</select></td>
<td><input type="text" name="income.EconomicActivityIncomeDeclarations[${SomeNumber}].GrossIncome" /></td>>
</tr>
</script>
}
이 작업을 위해 선택과 text_field 모두의 이름 속성이 ... 열쇠입니다
그렇지 않을 일을 modelbinding ... 내가 생각하는 것 그 SomeNumber 변수가 새로운 Date.GetTime로 설정되어있는 경우() 모델 바인딩은 잘 작동해야합니다 ...실제로 저는 아약스의 필요성을 알지 못합니다.하지만 다른 주제가 있습니다. 단지 아약스없이이 작업을 수행 할 수있는 방법을 찾지 못했습니다. 바로 지금하고 싶습니다. templat을 얻는다. 전자 양식을 작성하고 목록의 맨 아래에 양식 요소를 추가하십시오.
... 내가 – ignaciofuentes
http://stackoverflow.com/questions/5201845/problem-with-asp-net-mvc-modelbinding-behavior 것을 시도 할 것이다 참조 – ignaciofuentes