show the controller function signature and the ajax code. we can not guess what you are doing wrong.
Not getting value from Ajax in controller function
Hi All,
From my jquery Ajax function, I am passing value to .net core controller function. But its not getting in the controller function. But when I check browser network->payload value there. But not passing to function. I tried Json. stringify, without stringify etc. How can I solve this issue
Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
3 answers
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2022-03-04T17:37:58.123+00:00 -
satya karki 996 Reputation points MVP
2022-03-05T16:06:54.677+00:00 Hi @Binumon George , If you share your code then we can help you what is an issue there. However, I have written articles for sending data to Controller using Ajax by two methods. I think it will be helpful for you. You can check the below articles:
https://www.c-sharpcorner.com/article/how-to-post-data-in-asp-net-core-using-ajax/
https://www.c-sharpcorner.com/article/how-to-post-data-in-asp-net-using-ajax-without-json-form-serializer/ -
Arokia Dominic Raj 0 Reputation points
2023-10-05T14:10:13.0133333+00:00 Hi All,
I also facing the same issue while pass parameter from view to controller in .net core 6 and 7.
HTML
<head> <meta name="viewport" content="width=device-width" /> <title>Index</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> <script type="text/javascript"> $(function () { $("#btnGet").click(function () { $.ajax({ type: "POST", url: "/Home/Index", data: { "name": $("#txtName").val() }, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert("Name: " + response.Name + " City: " + response.City + "Phone:" + response.Phone); }, failure: function (response) { alert(response.responseText); }, error: function (response) { alert(response.responseText); } }); }); }); </script> </head> <body> <input type="text" id="txtName" /> <input type="button" id="btnGet" value="Submit" /> </body>