I work on .NET core 7 MVC razor page . I face issue I can't fill check boxes Id StockTake and ShelfLabelPrint by using ajax request to this function RelatedUserAccessPermission
URL below I run it on browser to access function RelatedUserAccessPermission
public JsonResult OnGetRelatedUserAccessPermission(int UserId)
{
var UserAccess = _db.UserAccess.ToList();
return new JsonResult(UserAccess);
}
so I need to call function OnGetRelatedUserAccessPermission from page model using ajax request .
so I need to make ajax request for that URL ?handler=RelatedUserAccessPermission
Access Rights 1 meaning it check true
Module Code 1,2 values of Id StockTake represent id 1 and ShelfLabelPrint represent id 2 based on UserId 1220
on AddUserAccess.cshtml
Submit
User ID
Stock Take
Shelf Label Print
Transfer
How to make ajax request Fill 2 check boxes when button submit click
$(document).ready(function () {
$('#FillCheckBox').click(function () {
//How to Make Ajax Request Fill CheckBoxes
});
});
for more details what I expect


Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 10, 2023, 8:59 AM EDT
To make an AJAX request to fill the checkboxes when the "Submit" button is clicked, you can use jQuery's
$.ajax()function. Here's an example of how you can modify your code to achieve this:$(document).ready(function () { $('#FillCheckBox').click(function () { var userId = $('#useraccess-id').val(); $.ajax({ url: '/AddUserAccess?handler=RelatedUserAccessPermission&UserId=' + userId, type: 'GET', success: function (data) { $.each(data, function (index, value) { if (value.MODULECODE == 1) { $('#StockTake').prop('checked', true); } if (value.MODULECODE == 2) { $('#ShelfLabelPrint').prop('checked', true); } if (value.MODULECODE == 3) { $('#Transfer').prop('checked', true); } }); }, error: function (error) { console.log(error); } }); }); });Gives this a Try
ahmed salahRank #2,240 · 628 reputationPosted May 10, 2023, 9:32 PM EDT
it working but not perfect
meaning checkbox #StockTake and #ShelfLabelPrint checkbox checked but after checked
it make strange action not checked
meaning some behaviour affect on check box
so it checked but quickly after less than second it not checked why
ahmed salahRank #2,240 · 628 reputationPosted May 10, 2023, 9:49 PM EDT
i gotted issue but i don't know how to solve it please
the proplem is method type is post
so after remove method of form post it working so why and how to solve it
Working perfect Submit User ID Stock Take Shelf Label Print Transfer and below Not Working because method="post" Submit User ID Stock Take Shelf Label Print Transfer so please how to solve this issueso please how to solve this issue