Version 7.0.0 MVCCore & JQuery
I need to pass the ID of a newly created record through the event bus so I can take action inside the subscribers. I get the ID using the InsertAndGetIdAsync method of the repository and that works fine. When I try to insert the id value to the event trigger I an Object [object ] error. on the subscription side I get ID: undefined Here is my code.
Note: newLabRequestId is an Object [object] data.Id is undefined
<br> AppService returns newly inserted record ID or -1
public async Task<int> CreateOrEdit(CreateOrEditLabRequestDto input)
{
int labRequestId;
if(input.Id == null){
labRequestId = await Create(input);
}
else{
await Update(input);
labRequestId = -1;
}
return labRequestId;
;
}
Create record in modal view. EventBus triggers but does not and pass the new through to the subscribers
var newLabRequestId = _labRequestService.createOrEdit( labRequest
).done(function () {
abp.notify.info(app.localize('SavedSuccessfully'));
_modalManager.close();
abp.event.trigger('app.createOrEditLabRequestModalSaved', { Id: newLabRequestId });
}).always(function () {
_modalManager.setBusy(false);
});
Eventbus subscription
//Event Bus Registration
abp.event.on('app.createOrEditLabRequestModalSaved',
function (data) {
if (data.Id !== -1) {
// View lab request for print
//window.location.href = "/LabRequest/ViewLabRequestModal/" + data.Id;
}
});
5 Answer(s)
-
0
What does
console.log(data);
show? At first glance your code looks correct, as I'mdoing something similar, however, what is your Create() method returning? You may also want to try just returning a number right away (skip all your logic), to see if it's a problem with your return value or your javascript to help with troubleshooting -
0
dnard82, thanks for the answer. I have tried to return just a number both from the Create() method and the modal. The Id value never gets passed through the event bus back to the subscribers.
here is the CreateOrEdit and Create methods
public async Task<int> CreateOrEdit(CreateOrEditLabRequestDto input) { int labRequestId; if(input.Id == null){ labRequestId = await Create(input); } else{ await Update(input); labRequestId = -1; } return labRequestId; ; } [AbpAuthorize(AppPermissions.Pages_LabRequest_Create)] private async Task<int> Create(CreateOrEditLabRequestDto input) { var labRequest = ObjectMapper.Map<LabRequest>(input); if (AbpSession.TenantId != null) { labRequest.TenantId = (int?) AbpSession.TenantId; } await _labRequestRepository.InsertAndGetIdAsync(labRequest); return labRequest.Id; }
I will keep working on this for now and post back if I find a solution
-
0
Have you re-run
npm run create-bundles
? -
0
I I have from the MVC project folder.
-
0
Got it figured out... Here is the code that works..
Create Modal
_labRequestService.createOrEdit(labRequest ).done(function (data) { abp.notify.info(app.localize('SavedSuccessfully')); _modalManager.close(); abp.event.trigger('app.createOrEditLabRequestModalSaved', { id: data }); }).always(function () { _modalManager.setBusy(false); });
Event subscription and action
//Event Bus Registration abp.event.on('app.createOrEditLabRequestModalSaved', function (data) { if (data !== -1) { // View lab request for print _viewLabRequestModal.open({ id: data.id }); } });