I want read returned value from this method:
public ActionResult ClientIsBlocked(int? clientId)
{
if (!clientId.HasValue)
return Json(null);
bool isBlocked = false;
try
{
isBlocked = this.clientsProvider.GetClientById(clientId.Value).IsBlocked;
}
catch
{
// logg
}
return Json(isBlocked);
}
in java script in my view. It should be async/ajax. How to do that? It is my js code in view.
function isBlocked(id) {
$.ajax({
contentType: "application/json; charset=utf-8",
dataType: "json",
type: "GET",
url: '@Url.Action("ClientIsBlocked", "CustomerManagement", new { Area = "CustomerManagement" })',
data: JSON.stringify({ 'clientId': id }),
success: function(data) {
if(!data.success) {
}
}
})
try {} catch {}really should do something if it is the production code... Not just eating the exception.datainside yoursuccessshould be boolean type, theisBlockedvalue. Just check this like thisconsole.assert(typeof(data) == "boolean")