Open Closed

Send info about created entity ID(json) from modal window to parent grid using modal.setResult #1479


User avatar
0
cleverplatform created

I'm checking your demo application Acme.BookStore - in Acme.BookStore.Web -

  1. the modal is prepared as razor page Pages/Books/CreateModal with get / post method where is:

public async Task<IActionResult> OnPostAsync() { await _bookAppService.CreateAsync(ObjectMapper.Map<CreateBookViewModel, CreateUpdateBookDto>(Book)); return NoContent(); } 2. in index.js I see createModal.onResult method where is only grid refresh.

createModal.onResult(function () { dataTable.ajax.reload(); });

  1. I want to send created entity Id into onResult js method, but im not sure how to set it even I try it:
  • send json object from OnPostSAsync which looks: new JsonResult(new { CategoryId = item.Id } )
  • createModal.setResult and createModal is defined as global
  • but still I don't know how to access it, because when onPost method ended I need to set setResult property but not sure where

I expected to use "UnobtrusiveJavaScript" approach to return JSON from Post into onSuccess jabvascript method, but it is not fired, even I rewrite Ajax.BeginForm into .net COre version (per source: https://www.aspsnippets.com/Articles/AjaxBeginForm-OnSuccess-not-firing-in-ASPNet-MVC.aspx)

<form class="layui-form" asp-action="CategoryAdd" data-ajax-success="onSuccess" data-ajax="true" data-ajax-method="POST"></form> (per https://dotnetthoughts.net/jquery-unobtrusive-ajax-helpers-in-aspnet-core/)

thanks

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

2 Answer(s)
  • User Avatar
    1
    enisn created
    Support Team .NET Developer

    Hi cleverplatform,

    Have you ever tried to return object instead of NoContent() from modal page:

    public async Task<IActionResult> OnPostAsync()
    {
        var created = await _bookAppService.CreateAsync(ObjectMapper.Map<CreateBookViewModel, CreateUpdateBookDto>(Book));
        return new OkObjectResult(created);
    }
    

    And add parameters to your javascript function to handle that object.

    createModal.onResult(function (result, response) 
    { 
        // response.responseText is your returned object.
        alert(response.responseText.id);
        dataTable.ajax.reload(); 
    });
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    cleverplatform created

    works like charm! Thanks a lot

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.