我正面临从asp.net web api(返回fron AspNetUsers表)返回此Id值作为Json。这可以将它作为Json返回,然后在Jquery中获取它吗?现在我得到零因为这可能不会像Json那样返回。提前谢谢!
public IHttpActionResult GetDepId()
{
var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
string name = User.Identity.Name;
var depId = manager.Users.Where(d => d.Email == name).Select(c => c.DepartmentId).FirstOrDefault();
return Ok(depId);
}
然后在jquery中:
function GetDept() {
$.ajax({
url: '/Api/userdp', // userdp is my controller
type: 'GET',
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
result; // failed even this result.Email;
},
error: {
}
});
}
答案 0 :(得分:0)
据我所知,你不能那样使用Ok()
。请尝试在控制器中使用return new ObjectResult(depId);
。
return Ok(string.Format("id:{0}", depId.ToString()));