지금 사용자는 JQuery로 버튼을 클릭합니다. 매번 새로운 양식을 동적으로 추가합니다. JQuery 또는 C#에서 인덱스를 업데이트 할 수있는 방법이 필요하므로 다음과 같은 형식이 있습니다. html은 ASP.NET MVC의 사용자 정의 컨트롤에서 만들어집니다. 인덱스에 문자열을 사용하려했지만 모델 바인딩을 제대로 수행하지 않았습니다. 나는 다음과 같은 블로그 link textASP.NET MVC에서 모달 바인딩 지원을위한 jQuery로 html 테이블 업데이트
// Jquery that handles user click event of the button
// Jquery that handles user click event of the button
// Jquery that handles user click event of the button
$(".addDetail").click(function() {
if ($("#rateFormContainer").css("display")!= "none") {
$.ajax({
url: "/Rates/NewRateDetail/",
cache: false,
success: function(html) {
$("#rdContainer").append(html);
}
});
$("#rateDetailMsg").empty()
}
});
// The end result of the view, what I want to do
// The end result of the view, what I want to do
// The end result of the view, what I want to do
// Update the Index to 0 for this element
<input type="hidden" value="0" name="RateDetail.Index" id="RateDetail_Index">
<input type="text" value="" name="RateDetail[0].EffectiveDate" id="RateDetail[0]_EffectiveDate">
// Update the Index to 1 for this element
<input type="hidden" value="1" name="RateDetail.Index" id="RateDetail_Index">
<input type="text" value="" name="RateDetail[1].EffectiveDate" id="RateDetail[1]_EffectiveDate">
// Update the Index to 2 for this element
<input type="hidden" value="2" name="RateDetail.Index" id="RateDetail_Index">
<input type="text" value="" name="RateDetail[2].EffectiveDate" id="RateDetail[2]_EffectiveDate">
// Use JQuery to update all items to correct indexes on sumbmit
<input type="submit" class="prettyButton" value="Submit">
// ASP.NET MVC user control code
// ASP.NET MVC user control code
// ASP.NET MVC user control code
// ASP.NET MVC user control code
<%=Html.Hidden(Resources.RSINET.RateDetailIndex, "0")%>
<table class="prettyForm">
<thead>
<th colspan="2">Add Rate Details</th>
</thead>
<tr>
<td>Effective Date</td>
<td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceEffectiveDate)%> <a href="javascript:NewCal('RateDetail[<%="0"%>].EffectiveDate','mmddyyyy')"><img src="../../Content/Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/></a></td>
</tr>
<tr>
<td>Expiration Date</td>
<td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceExpirationDate)%> <a href="javascript:NewCal('RateDetail[<%="0"%>].ExpirationDate','mmddyyyy')"><img src="../../Content/Images/cal.gif" width="16" height="16" border="0" alt="Pick a date"/></a></td>
</tr>
<tr>
<td>Condition Type</td>
<td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceConditionType, ViewData.Model.CondT, "Choose Option")%></td>
</tr>
<tr>
<td>Condition Value</td><td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceConditionValue)%></td>
</tr>
<tr>
<td>Rate</td><td><%=Html.TextBox(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceRate)%> </td>
</tr>
<tr>
<td>Unit</td><td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceUnit, ViewData.Model.Unit, "Choose Option")%></td>
</tr>
<tr>
<td>Status</td>
<td><%=Html.DropDownList(Resources.RSINET.RateDetailBrace + "0" + Resources.RSINET.BraceActiveItem, ViewData.Model.Active, "Choose Option")%></td>
</tr>
</table>
i는 인덱스 2는'RateDetail [0] _EffectiveDate' 바로'RateDetail [2] _EffectiveDate'되고 싶어, 당신이 거기에 오타가 생각? –
또한 귀하의 게시물에있는 코드는 귀하가 원하는 방식입니다. 당신이 시작하는 것을 우리에게 보여줄 수 있습니까? –
예, 당신은 핵심입니다. 나는 그것을 고쳤다. – user154366