C# API控制器可以';在mvc asp.net的浏览器中找不到
我是C# API控制器可以';在mvc asp.net的浏览器中找不到,c#,asp.net-mvc,asp.net-web-api,C#,Asp.net Mvc,Asp.net Web Api,我是单页应用程序的新手。我创建了一个webapi,您可以在这里看到: using System; using System.Collections.Generic; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; using System.Web.
单页应用程序的新手。我创建了一个webapi
,您可以在这里看到:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebApplication6.Models;
namespace WebApplication6.Controllers
{
public class ManageStudentInforAPIController : ApiController
{
private SchoolManagementEntities db = new SchoolManagementEntities();
// GET: api/ManageStudentsInfoAPI
public IQueryable<Student> Get()
{
return db.Students;
}
}
}
我的问题在哪里。你需要的任何细节我都可以发布。我正在使用vs2015
您尝试调用控制器作为
这应该可以如果您尝试按以下方式调用控制器
这应该会起作用您在ManageStudentInforAPI
之前错过了api
。尝试用http://localhost:5411/api/ManageStudentInforAPI
或者,您可以将[Route(“Route”)]
添加到控制器或方法中,然后调用http://localhost:5411/api/route
在ManageStudentInforAPI
之前,您错过了api
。尝试用http://localhost:5411/api/ManageStudentInforAPI
或者,您可以将[Route(“Route”)]
添加到控制器或方法中,然后调用http://localhost:5411/api/route
像这样调用apihttp://localhost:5411/api/ManageStudentInforAPI
或者,如果您想要自定义api url,则可以如下设置路由
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebApplication6.Models;
namespace WebApplication6.Controllers
{
public class ManageStudentInforAPIController : ApiController
{
private SchoolManagementEntities db = new SchoolManagementEntities();
// GET: api/ManageStudentsInfoAPI
[Route("api/MyApi")]
public IQueryable<Student> Get()
{
return db.Students;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Web.Http;
使用System.Web.Http.Description;
使用WebApplication6.Models;
命名空间WebApplication6.控制器
{
公共类管理器StudentInfo控制器:ApiController
{
私立学校管理实体db=新建学校管理实体();
//获取:api/ManageStudentsInfoAPI
[路线(“api/MyApi”)]
公共IQueryable Get()
{
返回db.Students;
}
}
}
然后像这样调用apihttp://localhost:5411/api/MyApi
像这样调用apihttp://localhost:5411/api/ManageStudentInforAPI
或者,如果您想要自定义api url,则可以如下设置路由
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Description;
using WebApplication6.Models;
namespace WebApplication6.Controllers
{
public class ManageStudentInforAPIController : ApiController
{
private SchoolManagementEntities db = new SchoolManagementEntities();
// GET: api/ManageStudentsInfoAPI
[Route("api/MyApi")]
public IQueryable<Student> Get()
{
return db.Students;
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
使用System.Linq;
Net系统;
使用System.Net.Http;
使用System.Web.Http;
使用System.Web.Http.Description;
使用WebApplication6.Models;
命名空间WebApplication6.控制器
{
公共类管理器StudentInfo控制器:ApiController
{
私立学校管理实体db=新建学校管理实体();
//获取:api/ManageStudentsInfoAPI
[路线(“api/MyApi”)]
公共IQueryable Get()
{
返回db.Students;
}
}
}
然后像这样调用apihttp://localhost:5411/api/MyApi
我遇到了这个错误:这个XML文件似乎没有任何与之相关的样式信息。文档树如下图所示。为什么不返回结果?我遇到了以下错误:此XML文件似乎没有任何与之关联的样式信息。文档树如下所示。为什么不返回结果?请添加路由配置。默认达到apiapi/controller
请添加路由配置。默认达到apiapi/controller