jquery – Controller not Binding with Data when sending ajax Json Post .Net 4.7
I am trying to send a simple Post to a controller .Net 4.7 via an ajax call in my Javascript. Pretty typical and the data is not coming through to my controller. I have added all attributes I can think of. The reques is expecting an System.Object but even trying a simple string fails. My breakpoint is getting hit. So it is finding the controller but the object request variable has no data.
My Javascript:
$.ajax({
url: "/Accounts/Summary/Person",
type: "post",
data: { "Test": "Test"},
dataType: "json",
statusCode: {
200: function (data) { }
},
});
Controller:
[System.Web.Http.HttpPost]
[Route("Person")]
public Response<GetResponse> Person
([FromBody][Bind(Include = "Test")] object request) // object has no data
{
return new Response<GetResponse>()
{
Data = new GetResponse()
{
ResponseBody = response.ToString(),
}
};
}
Area Registration:
context.MapRoute(
name: "Accounts-Person",
url: "Accounts/Summary/Person",
defaults: new { controller = "Summary", action = "Person", id = UrlParameter.Optional }
);
Read more here: Source link