问题描述
这是我的webapi控制器
This is my webapi controller
public class CategoryController : ApiController
{
List<category> category;
public class DataResult
{
public List<category> Category { get; set; }
}
#region Categories
public DataResult GetCategories()
{
DataResult result = new DataResult();
try
{
using (MyDB db = new MyDB())
{
category = db.Category.OrderBy(c => c.Name).ToList();
}
if (category == null)
{
throw new HttpResponseException(
Request.CreateResponse(HttpStatusCode.NotFound));
}
else
{
result.Category = category;
return result;
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
这是我的jquery调用document.ready()
This is my jquery calling in document.ready()
$.ajax({
url: "/api/Category",
type: "GET",
dataType: 'json',
success: function (data) {
alert('hai');
},
error: function (err) {
document.write(data);
}
});
从entityframework datacontext访问数据,但它没有显示alert.if传递静态数据然后它正在工作。
这里/ api /是foldername,类别是Api控制器。
调用控制器方法,但警报没有提高,为什么?
am accessing data from entityframework datacontext,but it is not displaying alert.if am passing static data then it is working.
here /api/ is foldername,Category is Api Controller.
It is calling the controller method,but alert is not raising,why?
推荐答案
从entityframework datacontext访问数据,但它没有显示alert.if传递静态数据然后它正在工作。
这里/ api /是foldername,类别是Api控制器。
调用控制器方法,但警报没有提高,为什么?
am accessing data from entityframework datacontext,but it is not displaying alert.if am passing static data then it is working.
here /api/ is foldername,Category is Api Controller.
It is calling the controller method,but alert is not raising,why?
这篇关于web api不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!