我想在 javascript 中創建的行中添加一個下拉列表,并將所選下拉項的 id 或文本與我的模型綁定。這是表格: <table id="LineItems" class="table table-bordered fixed"> <thead> <tr> <th width="10%" class="text-center"> @Html.Label("Qty") </th> <th width="40%" class="text-center"> @Html.Label("Description") </th> <th width="15%" class="text-center"> @Html.Label("Project Number") </th> <th width="10%" class="text-center"> @Html.Label("Unit Cost") </th> @if (Model.CanCreateCustSignOff == true) { <th width="10%" class="text-center"> @Html.Label("Custom Sign off") </th> <th width="20%" class="text-center"> @Html.Label("Approver") </th> } <th width="10%" class="text-center"> @Html.Label("Action") </th> </tr> </thead> <tbody id="lineItems"> </tbody> </table> <div> <input type="button" value="Add Line Item" class="btn btn-primary" onclick="addLineItem()" /> </div>查看模型 - 選擇列表項由控制器填充,由文本 = 用戶名和作為 Guid 的值組成。這些數據來自數據庫,我不知道會添加多少用戶。public List<string> Approvers { get; set; }public class LineItems{ public int Qty { get; set; } public string Description { get; set; } public decimal UnitCost { get; set; } public decimal LineItemCost { get; set; } public string ProjectNumber { get; set; } public bool CustSignOff { get; set; } public string ApproverId { get; set; } public Guid? ProjectId { get; set; } }Javascript - 我已經能夠使用下面的方法成功綁定使用我的模型創建的所有行的條目。
如何使用 Javascript 將下拉列表添加到 MVC 中的動態行并將值綁定到模型
瀟瀟雨雨
2022-06-16 17:23:05