I’ve a c# class like below sample code
public IActionResult OnPostTranJarray(int transaction_number, string cardholder)
{
dynamic Trans = GetTransactions(transaction_number,cardholder);
return Trans;
}
OR
public JArray Transactions { get; set; }
public void OnGet(int transaction_number)
{
Transactions = GetTransactions(transaction_number);
}
just wanted to Make a post call inside the IndexModel Class. I’ve use these below code in jquery
$.post("https://localhost:7197/Transactions?handler=TranJarray?transaction_number="+transactionNumb+"&cardholder="+cardHolderName, response => {
alert("response",response);
});
$.ajax({
type: "POST",
url: "https://localhost:7197/Transactions?handler=TranJarray?transaction_number="+transactionNumb+"&cardholder="+cardHolderName,
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (data)
{
alert("success");
fnLoadTbl();
}
});
But it’s not hitting to the method.. but if i make ajax GET Request to OnGet method it’s hitting but not returning any value. so let me know if you have any idea. Thanks..
2
Answers
Finally i got the solution by doing these
We've to create a model class like this
2.Created a onpost method
3.In frontend we should have and a type="submit" button inside it
Then it's perfectly working.. but thanks for those who tried to answer it
In order to return JSON from your
OnGet
method, change the return type fromvoid
toIActionResult
and return aJsonResult
, e.g.: