I have a web page ASP.NET Core MVC with a data list and each one is an ID number for click with a button using jQuery but it’s not working; only works in the first ID Number and after clicking the next ID number nothing happens and should click ID number to be refresh.
What am I doing wrong? Thanks for your help.
Data list of 5 items with ID Number to click one at a time, if I click 32345 it will get data info and refresh the data list page. If I click the next 857487 ID number same thing.
32345
Sensor 1
8/12/2022
857487
Sensor 2
06/04/2022
214875
Sensor 3
7/06/022
87955
Sensor 4
05/22/2022
<%if (Model != null && Model.Count() > 0)
{
foreach (Sensor item in Model)
{
DataMessage message = item.LastDataMessage;
%>
<div class="sensorDots table-fixed" style="width:100%; margin: 0px; display: flex; ">
<button style ="border: 0px; background: transparent; margin: 10px; display: flex;" type="button" data-id="<%:item.SensorID%>" id="btn_SingleSensorID" title="click to update the Sensor ID: <%:item.SensorID %>">
<div class="sensoricon” style="height: 15px; width:15px; margin: 1px; margin-right: 1px; text-align: center; cursor: pointer; line-height: 15px; background: <%=item.sensorID%>" ></div>
</button>
</div>
<%}
}%>
}
<script type="text/javascript">
$("#btn_SingleSensorID").click(function () {
let sensorID = $(this).data("id");
$.post("/SendDirtyFlags/", { "id": sensorID, }, function (data) {
if (data == "Success") {
refreshSensorList(sensorID);
}
else {
alert(data);
}
});
});
function refreshSensorList(sensorID) {
$('#btn_SingleSensorID').html("<img alt='Loading...' src='/content/images/ajax-loader.gif'/>");
$.post("/SendDirtyFlags/", { "id": sensorID}, function (data) {
$('#btn_SingleSensorID').html(data);
window.location.href = window.location.href;
});
}
</script>
[HttpPost]
public ActionResult SendDirtyFlags()
{
if (!MonatSession.CustomerCan("Can_Access")) return Content("Unauthorized");
string content = "Success";
try
{
var senslist = Sensor.LoadByCsNetID(1);
foreach (var sens in senslist)
{
sens.GeneralConfigDirty = true;
sens.SetDefaults(false);
sens.Save();
}
}
catch (Exception ex)
{
ex.Log("SensorController.SendDirtyFlags[Post] ");
content = "Failed: " + ex.Message;
}
return Content(content);
}