thanks for help yidan
but still same error
controller
public class PayTabsController : BaseController
{
public IActionResult OnGetAddress(string addressId, string customerId)
{
var customer = _workContext.GetCurrentCustomerAsync().GetAwaiter().GetResult();
if (string.IsNullOrEmpty(addressId) || addressId == "0" || customerId != customer.Id.ToString())
{
return Json(new
{
FirstName = customer.FirstName,
LastName = customer.LastName,
PhoneNumber = customer.Phone,
Email = customer.Email
});
}
else
{
Address address = _addressService.GetAddressByIdAsync(int.Parse(addressId)).GetAwaiter().GetResult();
return Json(new
{
address.FirstName,
address.LastName,
address.PhoneNumber,
address.Email,
Address = address.Address1,
address.City,
State = address.Address2
});
}
}
}
routeprovidor
public void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
{
endpointRouteBuilder.MapControllerRoute(name: "OnGetAddress",
pattern: $"OnGetAddress",
defaults: new { controller = "PayTabs", action = "OnGetAddress" });
}
and ajax
function getAddress(addressId) {
if (addressId) {
$("#main-loader").show("in");
$.ajax({
type: "POST",
url: '/OnGetAddress',
//url: '/PayTabs/OnGetAddress?addressId=' + addressId + '&customerId=' [email protected]().GetAwaiter().GetResult().Id,
data: {addressId: addressId,customerId: @workContext.GetCurrentCustomerAsync().GetAwaiter().GetResult().Id},
contentType: "application/json; charset=utf-8",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN", $('input:hidden[name="__RequestVerificationToken"]').val());
},
dataType: "json"
}).done(function (data) {
$("#FirstName").val(data.FirstName);
$("#LastName").val(data.LastName);
$("#PhoneNumber").val(data.PhoneNumber);
$("#Email").val(data.Email);
$("#City").val(data.City);
$("#Address").val(data.Address);
getDistricts(data.City, data.State);
$("#main-loader").hide("in");
}).fail(function (x, y, z) {
$("#main-loader").hide("in");
})
}
else {
}
}
error
POST https://localhost:44369/OnGetAddress 400
please help