Open Closed

Ajax post data is null on server side #6270


0
entripy created

Hi, I am using following ajaz call with abp.ajax to controller.

$("#mapBtn").on("click", function (e) {
            var data = buildDataObject();
            abp.ajax({
                url: "Map",
                data: JSON.stringify({
                ColumnName1: $("#selector1").val(),
                HasHeader: $("#selector2").is("checked"),
                
            }),
                content: "application/json; charset=utf-8",
                type:'post'
            }).done(function (data) {
                abp.notify.success('Created  ');});
          
        });

My model class:

public class MyClass {
        public string ColumnName1 { get; set; }
        public bool HasHeader { get; set; }
    }

My controller action is as follows: I used [DisableValidation] on the controller.

[HttpPost]
public async Task<ActionResult> Map([FromBody] MyClass data)
        {
                       // data  is null 
            return View("Import");
        }

data is always null. When I replaced myclass with dynamic type; i do get data back but its not in a format I can convert to my model. Can you point me to what is missing?


3 Answer(s)
  • 0
    maliming created

    try remove: JSON.stringify

    data: {
        ColumnName1: $("#selector1").val(),
        HasHeader: $("#selector2").is("checked")
    };
    
  • 0
    entripy created

    I tried that already. its not working.

  • 0
    ryancyq created

    Please share the name of your controller and the ajax network request in your browser console/network panel.