This code is being used to send id
of an anchor element on its click event from a view to a controller using ajax and jQuery.
<script type="text/javascript">
$(document).on('click', 'a', function () {
$.ajax({
type: 'POST',
url: '@Url.Action("/brandsOfACategory")',
contentType: 'application/json; charset:utf-8',
data: JSON.stringify(this.id)
})
});
</script>
Action Method used to catch this string is:
[HttpPost]
public ActionResult brandsOfACategory(string id)
{
return View();
}
But string id
in this action method is coming as null. I checked Network tab of Chrome developer tool for Request Payload to check the value of the parameter and it is an object and not a string. It's screen is uploaded here: https://i.stack.imgur.com/hE240.jpg