Open Closed

Ajax post data is null on server side #6270

entripy created

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

$("#mapBtn").on("click", function (e) {
            var data = buildDataObject();
                url: "Map",
                data: JSON.stringify({
                ColumnName1: $("#selector1").val(),
                HasHeader: $("#selector2").is("checked"),
                content: "application/json; charset=utf-8",
            }).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.

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)
  • 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.

  • 0
    aggarwal created

    Hi @entripy

    I am facing same issue.

    Can you please post the solution?

    Cheers, Vikas