I use jQuery
and send data with the POST
method. But in the server method the values are not coming. What could be the error?
client
Use [FromBody]
before the param. It's check and Get the Property value in body otherwise it's check the Url Querystring.
Example:
[HttpPost]
public JObject AddTag([FromBody] int parentid,[FromBody]string tagname)
{
}
[HttpPost]
public JObject AddTag([FromBody] {ModelName} parent)
{
}
Try extracting your params into a separate DTO class and do it like that:
public class ParentDTO
{
public int parentId{get; set;}
public string tagName{ get; set;}
}
[HttpPost]
public JObject AddTag([FromBody] ParentDTO parent)
{
}
Change your ajax to this
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "./AddTag?parentId="+42+"&tagName="+'isTagName',
dataType: "json",
success: function (response) {
// ...
}
});