Я создаю следующую сущность:
Код: Выделить всё
public class CustomResponse
{
public bool isValid { get; set; }
public string message { get; set; }
public T data { get; set; }
public CustomResponse()
{
}
public CustomResponse(bool isValid, string message, T data)
{
this.isValid = isValid;
this.message = message;
this.data = data;
}
public CustomResponse(bool isValid, string message)
{
this.isValid = isValid;
this.message = message;
}
}
Код: Выделить всё
[HttpGet]
[Route("all")]
public CustomResponse All()
{
try
{
var result = bllClients.All();
return new CustomResponse(true, "sucessful", result);
}
catch (Exception ex)
{
return new CustomResponse(false, ex.Message);
}
}
Код: Выделить всё
function getAll() {
$.ajax({
....
....
success: function(data) {
if(data.isValid) {
//do something
} else {
alert(data.message);
}
}
});
}
или есть какой-то более оптимальный способ?
Подробнее здесь: https://stackoverflow.com/questions/483 ... eb-api-net
Мобильная версия