Я вызываю функцию C # из js в ASP.NET.Проблема в том, что переменная SQL bit
отображается как «неопределенная» при получении в ответ.Все остальные переменные извлекаются успешно.
Оператор SQL:
SELECT
[UserID], [Name], [Badge], [Status],
CASE WHEN [isAdmin] = 0 THEN 'No'
WHEN [isAdmin] = 1 THEN 'Yes'
END AS [isAdmin]
FROM Admin
js:
function Retrieve() {
$.ajax({
type: "POST",
url: "UsersList.aspx/Retrieve",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successRetrieve,
failure: function (response) {
alert("Error");
}
});
}
function successRetrieve(response) {
alert(response.d[i].IsAdmin); // "undefined"
alert(response.d[i].Status); // "retrieved correctly"
alert(response.d[i].Name); // "retrieved correctly"
}
Веб-служба C #:
while (dr.Read())
{
ListOfUsersList.Add(
new User
{
UserID = dr["UserID"].ToString(),
Name = dr["Name"].ToString(),
Badge = dr["Badge"].ToString(),
Status = dr["Status"].ToString(),
isAdmin = dr["isAdmin"].ToString(), // "when I debug it is yes"
});
}
User
класс:
public class User
{
public string UserID;
public string Name;
public string Badge;
public string Status;
public string isAdmin;
}