abp.ajax({ Post Issue: Null Value being passed to the server side using abp.ajax({

Viewed 16

I'm having some problems passing the data from my razor page to the server. It is passing NULL value from my abp.ajax({. Is there anything I'm missing from my ajax or the server-side code:

I'm using RAZOR PAGES ABP Framework 5.3

MY AJAX:


      $("#frmDistrict").on("submit",
            function (event) {        
                event.preventDefault();
                const Url = $(this).attr("action");
                const formData = $(this).serialize();
                abp.ajax({
                    type: 'POST',
                    url: url,
                    data: JSON.stringify(formData)
                }).then(function (result) {
                    if (data.isValid) {
                        if (data.IsNew) {
                            abp.notify.success(data.retmsg);                  
                            window.location.href = data.returl;
                        } else {
    
                        }
                        abp.notify.success(data.retmsg);
    
                    } else {
                        DisplayModelStateErrors(data.retmsg);
                    }
                }).catch(function () {
                    alert("request failed :(");
                });
        });

MY SERVER CODE:

public async Task<JsonResult> OnPostAsync()
    {

        var rt = await Mediator.Send(new CreateDistrictCommand
        {
            District = district
        });

        if (rt.Failed) return new JsonResult(new { isValid = false, IsNew = true, retmsg = 
        rt.Message, sdata = rt.Data });

        var retmsg = "District " + rt.Data.Name + " Created successfully.";
        var returl = "/Districts/";
        return new JsonResult(new { isValid = true, IsNew = true, retmsg, returl });
    }

MY FORM


    <form method="post" id="frmDistrict" >
        <partial name="_AddEditDistrict" model="Model.District" />
    </form>

If I use the standard ajax call

``$.ajax({ it works fine

but abp.ajax({ doesn't work

Many thanks

Zak

0 Answers
Related