【发布时间】:2019-01-10 11:20:44
【问题描述】:
当我从下拉列表中选择一个值时,它应该使用 AJAX 根据下拉列表中的值更改表格。我不知道该怎么做。任何形式的帮助将不胜感激。
这里是下拉列表和表格的后端;
public ActionResult Representatives()
{
ViewBag.reps = db.tbl_Users.Where(x=>x.fk_Roleid==2).ToList();
var reps = db.tbl_CordinatorPayments.Include(t => t.tbl_Users).Where(x => x.fk_repId != null);
return View(reps.ToList());
}
这是下拉列表;
<select name="selectCity" id="CityDDL" class="form-control" style="width: 200px; height: 100%;" onchange="getValue()">
<option value="-1">--Select Rep--</option>
@foreach (var item in ViewBag.reps)
{
<option value="@item.id">@item.Name</option>
}
</select>
这是表格;
<table id="example" class="table table-bordered table-hover" style="text-align: center;">
<thead class="thead-light">
<tr>
<th>#
</th>
<th>Rep Name
</th>
<th>Member Name
</th>
<th>Ubl %
</th>
<th>Shirts %
</th>
<th>Membership %
</th>
<th>Total
</th>
<th>Date
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelitem => item.id)
</td>
<td>
@Html.DisplayFor(modelItem => item.tbl_Users.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.tbl_Member.Member_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.PercentageUblAMount)
</td>
<td>
@Html.DisplayFor(modelItem => item.PercentageShirtsAmount)
</td>
<td>
@Html.DisplayFor(modelItem => item.PercentageMembershipAmount)
</td>
<td>
@Html.DisplayFor(modelitem => item.Total)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
</tr>
}
</tbody>
</table>
这就是我获取下拉列表值的方式;
function getValue() {
var value = $("#CityDDL").val();}
然后我想在这样的 sql 查询中使用这个值;
select * from [tbl_CordinatorPayments] where fk_repId=id;
然后这个查询将填充我不知道该怎么做的表。 任何帮助,将不胜感激。谢谢!!!
【问题讨论】:
-
你的 C# 代码在哪里?
标签: c# sql asp.net asp.net-mvc