No, it didn't work. After selecting a group with the script code, I cannot operate the button on the data listed, otherwise it has nothing to do with the popup. I mean, I have a normal table for now, but when I press the button on the data that comes after selecting the group, it gives an error.
@Html.DropDownList("GRUP", (List<SelectListItem>)ViewBag.grups, "Gruplar", new { @class = "form-control", style = "margin-top:5px;width: 89%; height: 35px; font-size: 17px;", id = "ddlCountry" })
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#ddlCountry").on('change', function (e) {
$.ajax({
type: 'POST',
url: "/Cari/Search",
dataType: 'json',
data: { country: $(this).find('option:selected').val() },
success: function (response) {
$('#tblCustomers').hide();
$('#tblCustomers tbody').empty();
$.each(response, function (i, item) {
var STOKADI = item.STOKADI;
var STOKID = item.STOKID;
var RESIM = item.RESIM;
var ALIS = item.ALIS;
var SATIS = item.SATIS;
var MIKTAR = item.MIKTAR;
var rows = "<tr>" +
"<td><button type='button' class='btn btn-info popupModal' data-id='#urunekle_" + STOKID + "'>" + STOKID + "</button> </td>" +
"<td><img class='buyutec' src='" + item.RESIM + "' style='width:45px;height:45px' /> " + STOKADI + "</td>" +
"<td> Alış: " + ALIS + " ₺</td>" +
"<td> Satış: " + SATIS + " ₺</td>" +
"<td> Miktar: " + MIKTAR + " ₺</td>" +
"</tr>";
$('#tblCustomers tbody').append(rows);
});
$('#tblCustomers').show();
},
error: function () {
}
});
});
$("body").on("click", ".popupModal", function () {
var id = $(this).attr("data-id");
$(id).modal('show');
});
});
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#ddlCountry").on('change', function (e) {
$.ajax({
type: 'POST',
url: "/Cari/Search",
dataType: 'json',
data: { country: $(this).find('option:selected').val() },
success: function (response) {
$('#tblCustomers').hide();
$('#tblCustomers tbody').empty();
$.each(response, function (i, item) {
var STOKADI = item.STOKADI;
var STOKID = item.STOKID;
var RESIM = item.RESIM;
var ALIS = item.ALIS;
var SATIS = item.SATIS;
var MIKTAR = item.MIKTAR;
var rows = "<tr>" +
"<td><button type='button' class='btn btn-info popupModal' data-id='#urunekle_" + STOKID + "'>" + STOKID + "</button> </td>" +
"<td><img class='buyutec' src='" + item.RESIM + "' style='width:45px;height:45px' /> " + STOKADI + "</td>" +
"<td> Alış: " + ALIS + " ₺</td>" +
"<td> Satış: " + SATIS + " ₺</td>" +
"<td> Miktar: " + MIKTAR + " ₺</td>" +
"</tr>";
$('#tblCustomers tbody').append(rows);
});
$('#tblCustomers').show();
},
error: function () {
}
});
});
$("body").on("click", ".popupModal", function () {
var id = $(this).attr("data-id");
$(id).modal('show');
});
});
</script>
<table style="margin-top: 5px " id="tblCustomers" class="table table-dark table-striped">
<tbody id="mytable">
@foreach (var c in Model)
{
<tr>
<td style="width:15px">
<button style="height:45px" type="button" class="btn btn-info" data-toggle="modal" data-target="#urunekle_@c.STOKID">
<b>+</b>
</button>
<div class="modal" id="urunekle_@c.STOKID">
<div style="width: 95%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%)" class="modal-dialog" id="urunekle_@c.STOKID">
<div class="modal-content">
<div class="modal-body">
<div class="item">
<label style="color:black">Miktar</label>
<input style="height:50px; font-size:30px" type="number" name="MIKTAR" id="txtmiktar" class="form-control" value="1" />
<label style="color:black">Fiyat</label>
<input style="height:50px ; font-size:30px" type="text" name="FIYAT" id="txtfiyat" class="form-control" value="@((System.Data.SqlTypes.SqlMoney?)c.SATIS)" />
<input type="text" name="STOKID" id="txtstokid" class="form-control" value="@c.STOKID" hidden />
<input type="text" name="FISID" id="txtfisid" class="form-control" value="@ViewBag.fisid " hidden />
<input type="text" name="FIRMA" id="txtfirma" class="form-control" value="@ViewBag.firma" hidden />
<input type="text" name="CARIID" id="txtcariid" class="form-control" value="@ViewBag.cariid" hidden />
<input type="text" name="PLASIYER" id="txtplasiyer" class="form-control" value="@ViewBag.plasiyer" hidden />
<input type="text" name="YON" id="txtyon" class="form-control" value="1" hidden />
<input type="text" name="TARIH" id="txttarih" value="@DateTime.Today.ToString("dd.MM.yyyy")" class="form-control" hidden />
<br />
<button style="height:100px ; font-size:50px; margin-top:-10px" class="btn btn-danger form-control" id="urnek">Tamam</button>
<br />
<br />
<button style="top:3px" type="button" class="btn btn-dark form-control" data-dismiss="modal">Kapat</button>
</div>
<script type="text/javascript">
$("body").on("click", "#urnek", function () {
var g = {};
g.MIKTAR = $(this).closest('.item').find("#txtmiktar").val();
g.FIYAT = $(this).closest('.item').find("#txtfiyat").val();
g.STOKID = $(this).closest('.item').find("#txtstokid").val();
g.FIRMA = $(this).closest('.item').find("#txtfirma").val();
g.CARIID = $(this).closest('.item').find("#txtcariid").val();
g.PLASIYER = $(this).closest('.item').find("#txtplasiyer").val();
g.FISID = $(this).closest('.item').find("#txtfisid").val();
g.TARIH = $(this).closest('.item').find("#txttarih").val();
g.YON = $(this).closest('.item').find("#txtyon").val();
$.ajax({
type: "POST",
url: "/Cari/urunekle",
data: JSON.stringify(g),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
window.location.reload(1);
}
});
});</script>
</td>
<td>
@if (c.RESIM != null)
{
<span><img class="buyutec" src="@c.RESIM" style="width:45px;height:45px" /></span>
}
else
{
<span><img class="buyutec" hidden /></span>
}
<span>@c.STOKADI</span><br />
<span style="float: right;"> @((System.Data.SqlTypes.SqlMoney?)@c.SATIS) ₺</span>
<span style="margin-top:-9px; margin-left :50%">@c.MIKTAR Adet</span>
</td>
</tr>
}
</tbody>
</table>