I have an application where we are using entity framework and on button click an ajax call is made to save values.
Everything is working fine, but even if we try to click the save button, with no values, it gets saved in database as null or empty(takes space).
There is some minor error which I am overlooking, please help me out.
What I tried:
$.ajax({
type: "POST",
url: '~/SaveGroups',
data: {
GroupId: (GroupId == null ? -1 : GroupId),
counterId: (counterId == null ? -1 : counterId),
GroupCode: GroupCode,
GroupDesc: GroupDescription
},
success: function (result) {
if (result != null) {
$("#PartialGroupsTable").html(result.GroupsPageString);
$("#GCode").val('') //GCode is the name of the textbox
$("#GDescription").val(''); //GDescription is the other textbox
GroupId = -1;
}
},
complete: function () {
$("#GCode").empty();
$("#GDescription").empty();
},
error: function () {
alert("Details Not Saved. Please try again later");
}
});
Thanx in advance.