Javascript 如何通过单击按钮在数据表中动态添加razor下拉列表?
我有4列的数据表。我在我的第二个专栏里有下拉列表。我需要根据所选下拉列表值绘制剩余列 作为存储在字典中的值,我使用JSON调用从控制器获取值。我甚至得到了价值。我需要通过选择下拉选项加载这些。。我将这些下拉列表分别添加到第一行的第二个单元格中,最终能够加载受尊重的值。现在,我试图通过单击add按钮,将该下拉列表动态添加到每一行。它如何显示Javascript 如何通过单击按钮在数据表中动态添加razor下拉列表?,javascript,json,asp.net-mvc,datatables,Javascript,Json,Asp.net Mvc,Datatables,我有4列的数据表。我在我的第二个专栏里有下拉列表。我需要根据所选下拉列表值绘制剩余列 作为存储在字典中的值,我使用JSON调用从控制器获取值。我甚至得到了价值。我需要通过选择下拉选项加载这些。。我将这些下拉列表分别添加到第一行的第二个单元格中,最终能够加载受尊重的值。现在,我试图通过单击add按钮,将该下拉列表动态添加到每一行。它如何显示无效令牌或意外令牌错误。。如何修复dis 单行代码: <table cellspacing="1" cellpadding="2" style="widt
无效令牌
或意外令牌
错误。。如何修复dis
单行代码:
<table cellspacing="1" cellpadding="2" style="width: 100%;" id="tblAdd" class="table table-striped table-hover table-bordered table-hd">
<thead>
<tr class="gridheader">
<td style="width: 10%;">S.No</td>
<td style="width: 30%;">Id</td>
<td style="width: 30%;">Type</td>
<td style="width: 30%;">N O D</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>
@{
List<string> LE = new List<string>();
Dictionary<string, string> test2 = DictionaryUtil.GetLEDictionary();
if (test2 != null && test2.Count() > 0)
{
foreach (var item in test2)
{
if (item.Key != string.Empty) { LE.Add(item.Key); }
}
}
}
@Html.DropDownList("LE", new SelectList(@LE), "--Select Type--", new { @class = "form-control" })
</td>
<td> </td>
<td></td>
</tr>
</tbody>
</table>
用于在表中绘制单元格的Javascript:
<script type="text/javascript">
$(document).on('change', $("LE"), function (el) {
var LE = $("#LE").val();
var LEUrl = '@Url.Action("GetLEDetails")';
var t = $('#tblAdd').DataTable();
$.getJSON(LEUrl, { Type: LE }, function (returnedJson) {
var row = t.row(this);
var LT = returnedJson._LT;
var NOD = returnedJson._NOD;
t.cell(row, 2).data(LT).draw();
t.cell(row, 3).data(NOD).draw();
});
});
</script>
$(文档).on('change',$('LE')、函数(el){
var LE=$(“#LE”).val();
var LEUrl='@Url.Action(“GetLEDetails”);
var t=$('#tblAdd').DataTable();
$.getJSON(LEUrl,{Type:LE},函数(returnedJson){
var行=t行(本);
var LT=返回的JSON.\u LT;
var NOD=returnedJson.\u NOD;
t、 单元格(第2行).data(LT).draw();
t、 单元格(第3行).data(NOD.draw();
});
});
这将在第一行创建下拉列表,同时加载页面并在更改下拉列表时加载数据,现在我正在尝试加载预期结果
我的桌子是这样的
`
<table cellspacing="1" cellpadding="2" style="width: 100%;" id="tblAdd" class="table table-striped table-hover table-bordered table-hd">
<thead>
<tr class="gridheader">
<td style="width: 10%;">S.No</td>
<td style="width: 30%;">Id</td>
<td style="width: 30%;">Type</td>
<td style="width: 30%;">N O D</td>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td> </td>
<td> </td>
<td></td>
</tr>
</tbody>
</table>
`
美国号
身份证件
类型
诺德
剧本应该是这样的
<script type="text/javascript">
$(document).on('click', $("btnAdd"), function () {
var t = $('#tblAdd').DataTable();
var row = t.row(this);
@{
List<string> LE = new List<string>();
Dictionary<string, string> test2 = DictionaryUtil.GetLEDictionary();
if (test2 != null && test2.Count() > 0)
{
foreach (var item in test2)
{
if (item.Key != string.Empty) { LE.Add(item.Key); }
}
}
}
t.cell(row, 1).data(@Html.DropDownList("LE", new SelectList(@LE), "--Select Type--", new { @class = "form-control" })).draw();
}
</script>
$(文档)。在('单击',$(“btnAdd”),函数(){
var t=$('#tblAdd').DataTable();
var行=t行(本);
@{
List LE=新列表();
Dictionary test2=DictionaryUtil.GetLEDictionary();
if(test2!=null&&test2.Count()>0)
{
foreach(test2中的var项)
{
如果(item.Key!=string.Empty){LE.Add(item.Key);}
}
}
}
t、 单元格(第1行).data(@Html.DropDownList(“LE”,new SelectList(@LE),“--Select Type--”,new{@class=“form control”})).draw();
}
怎么做?我哪里出错了?同样,我们可以通过单击“删除”按钮删除这些选定的行吗?我不清楚…!是否要向dropdownlist添加值?我可以添加值和所有内容..我想将razor下拉列表添加到列Id下的数据表中。当我尝试单独/直接在下添加时,效果很好,但是t表示下一行未随此下拉列表一起创建。显然,我需要的是,我需要在单击btnAdd后在第二列中动态添加我的razor下拉列表。实际操作是,一旦我选择了下拉列表值,该行中的剩余单元格将根据dd值填充。一旦创建了一行,如果单击btnAdd,我需要第二行Id column必须显示下拉列表。先生,我的英语不是很好,请调整它。首先尝试在添加按钮上添加字符串值,如“Test”,然后一步一步向前移动step@PrashantPimpaleappend()不工作,错误显示未定义。但
t.cell(第2行).data(LT).draw();
这一行可以根据dd值绘制单元格值,效果很好。使用相同的方法,我尝试在我的第二个单元格t.cell(第1行)中添加下拉列表(@Html.DropDownList(“LE”,new SelectList(@LE),“--Select Type--”,new{@class=“form control”}))。draw();
,这一个对我不起作用。显示的错误是:"意外标记LT
变量的数据外观对我来说不清楚…!你想向dropdownlist添加值吗?我可以添加值和所有..我想将我的razor下拉列表添加到列Id下的datatable中。当我尝试单独/直接在下添加时,它可以正常工作,但下一行没有随此下拉列表一起创建..因此c显然,我需要的是,我需要在点击btnAdd后在第二列中动态添加我的razor下拉列表。实际操作是,一旦我选择了下拉列表值,该行中剩余的单元格将填充dd值。一旦创建了一行,如果我点击btnAdd,我需要第二行Id列必须显示下拉列表。先生,我的英语不是很好,请调整它。首先尝试添加字符串值,如“添加”按钮上的“测试”,然后一步一步向前移动step@PrashantPimpaleappend()不工作,错误显示未定义。但t.cell(第2行).data(LT).draw();
这一行可以根据dd值绘制单元格值,效果很好。使用相同的方法,我尝试在我的第二个单元格t.cell(第1行)中添加下拉列表(@Html.DropDownList(“LE”,new SelectList(@LE),“--Select Type--”,new{@class=“form control”}))。draw();
,这一个对我不起作用。显示的错误是:“意外标记LT
变量的数据外观
<script type="text/javascript">
$(document).on('click', $("btnAdd"), function () {
var t = $('#tblAdd').DataTable();
var row = t.row(this);
@{
List<string> LE = new List<string>();
Dictionary<string, string> test2 = DictionaryUtil.GetLEDictionary();
if (test2 != null && test2.Count() > 0)
{
foreach (var item in test2)
{
if (item.Key != string.Empty) { LE.Add(item.Key); }
}
}
}
t.cell(row, 1).data(@Html.DropDownList("LE", new SelectList(@LE), "--Select Type--", new { @class = "form-control" })).draw();
}
</script>