async Task Delete(string userId)
{
var boolval = false;
var modalresponse = await js.InvokeAsync<object>("swal", "Are you sure", "", "error", new { buttons = true });
if(modalresponse == null)
{
boolval = false;
}
else if (modalresponse.GetType().IsValueType)
{
boolval = true;
}
if (boolval)
{
// delete user
}
else
{
// do something else
}
}
I've been trying to use swal in my project.
In my razor page, I'm trying to show a popup and according to its respond I'll do something
@inject IJSRuntime js
var result = await js.InvokeAsync<bool>("swal", new
{
title = "Some title",
text = "Some text",
icon = "warning",
buttons = true,
});
if(result) {
// do something
}
else {
// do something else
}
Clicking OK works fine but clicking cancel crushes the app. Saying JSON value could not be converted to bool
If I give bool?
instead of bool
for a return type then clicking cancel, it says null object cannot be converted to value type
Also tried to use Convert.ToBoolean
and Convert.ToInt32
but no use
How can I catch if user clicks cancel?
Because as InvokeAsync
documentations point out the TValue
is a JSON-serializable return type which can not be serialized to bool
.
// Type parameters: // TValue: // The JSON-serializable return type.