Modal
Modal
<script>
$(document).ready(function () {
$('#add-btn').click(function(){
console.log('click call')
});
$(".editButton").click(function () {
const id = $(this).data("id");
const name = $(this).data("name");
const studentClass = $(this).data("class");
const rollNumber = $(this).data("roll");
$("#studentId").val(id);
$("#studentName").val(name);
$("#studentClass").val(studentClass);
$("#studentRoll").val(rollNumber);
$.ajax({
url: "/Student/Edit", // Update this to the correct Edit action URL
method: "POST",
data: formData,
success: function () {
alert("Student updated successfully!");
location.reload(); // Reload the page to reflect changes
},
error: function () {
alert("Error updating student!");
}
});
});
$.ajax({
url: `/Student/Delete/${id}`, // Update this to the correct
Delete action URL
method: "POST",
success: function () {
alert("Student deleted successfully!");
location.reload(); // Reload the page to reflect changes
},
error: function () {
alert("Error deleting student!");
}
});
});
});
</script>
<script>
// data save hoga (save buton k click honay pe)....
$(document).ready(function () {
$('#saveStudent').click(function () {
// Collect form data
var studentData = {
Name: $('#Name').val(),
Class: $('#Class').val(),
RollNumber: $('#RollNumber').val()
};
});
});
</script>
new
$(document).ready(function () {
$('#add-btn').click(function(){
$('#addMdl').modal('show');
});
$('#stsave').click(function () {
var studentData = {
Name: $('#Name').val(),
Class: $('#Class').val(),
RollNumber: $('#RollNumber').val()
};
$.ajax({
url: '/Student/Create',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(studentData),
success: function (response) {
alert('Student added successfully!');
$('#addStudentModal').modal('hide');
$('#addStudentForm')[0].reset();
location.reload();
},
error: function (xhr) {
console.error('Error:', xhr.responseText);
alert('Error: ' + xhr.responseText);
}
});
});
});