1 回答

TA貢獻1807條經(jīng)驗 獲得超9個贊
@{
for (int i = 0; i < 5; i++) { <tr>
<td> @Html.Editor("[" + i + "].QNo", new { htmlAttributes = new { @class = "form-control ", @type = "text",
@placeholder = " QNo", @required = "", @id = "txtQNo", @style = "width:60px;" } })</td>
<td> </td>
<td> @Html.DropDownList("[" + i + "].Question", new SelectList(string.Empty,"Value", "Text"), "Select Question",
new { @class = "form-control ", @id = "Question"+i, @style = "width:900px;" })</td>
</tr>
}
}
這將生成唯一的 id,如下所示 Question0、Question1、Question2、Question3、Question4
$("#ReflectionType").on("change", function (event) {
$.ajax({
type: "post",
url: "/Question/GetQuestions",
data: { TypeId: $('#ReflectionType').val() },
datatype: "json",
traditional: true,
success: function (data) {
debugger;
$.each(data, function (index, value) {
var markup = '';
for(let j = 0; j < 5; j++){
$("#Question"+j).append('<option value="' + value.Question + '">' + value.Question + '</option>');
}
});
}
});
如我所見,您的循環(huán)正在運行 5 次迭代,您可以以相同的方式運行它并附加來自 ajax 調(diào)用的數(shù)據(jù)?;蛘吣梢允褂?starts with selector 如下
$('[id^=Question]').each(function(index,element){
$(element).append('<option value="' + value.Question + '">' + value.Question + '</option>');
})
希望這能解決您的問題??鞓肪幋a!
- 1 回答
- 0 關(guān)注
- 121 瀏覽
添加回答
舉報