Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Ajax post data is null on server side #6270


User avatar
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?


4 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    try remove: JSON.stringify

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

    I tried that already. its not working.

  • User Avatar
    0
    ryancyq created
    Support Team

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

  • User Avatar
    0
    aggarwal created

    Hi @entripy

    I am facing same issue.

    Can you please post the solution?

    Cheers, Vikas