Why is Web API model binding so complicated by default: I tried a lot of combinations but none of them seem to work. This is ajax request:
var dataString = JSON.stringify({
request: Request
});
var request = Request;
$.ajax({
type: "POST",
data: '='+dataString,
// contentType: 'application/x-www-form-urlencoded',
contentType: "application/json; charset=utf-8",
dataType: "json",
This is controller:
public AccResultObject Post(string jezik, string page, string size, string sort,AccRequestViewModel model)
This is AccRequestViewModel
public class AccRequestViewModel
{
public AccRequestObject request { get; set; }
}
and this is AccRequestObject:
public class AccRequestObject
{
public int FM { get; set; }
public int Budget { get; set; }
public string WebCatID { get; set; }
public int Distance { get; set; }
}
Whatever I do, controller gets null value.
I tried this also. It seems very logical:
var dataString = JSON.stringify({
request: Request
});
$.ajax({
type: "POST",
data: dataString, ...
and controller receives AccRequestObject:
public AccResultObject Post(string jezik, string page, string size, string sort,[FromBody] AccRequestObjectmodel)
It works great except this small problem. Values are not binded.