C# ASP.Net-请求的资源不支持http方法';获取';
我正在编写一个控制器,以获得特定作者的特定评级的书籍。这是GET方法的代码:C# ASP.Net-请求的资源不支持http方法';获取';,c#,asp.net,C#,Asp.net,我正在编写一个控制器,以获得特定作者的特定评级的书籍。这是GET方法的代码: public IQueryable<Book> GetBooks(string context) { string rating = context.Split('?')[0]; string[] authors = context.context.Split('?')[1].Split(','); return db.Books.Where(s => authors.Contain
public IQueryable<Book> GetBooks(string context)
{
string rating = context.Split('?')[0];
string[] authors = context.context.Split('?')[1].Split(',');
return db.Books.Where(s => authors.Contains(s.AuthorName) && s.Rating == rating);
}
我得到这个错误:
请求的资源不支持http方法“GET”。
我做错了什么?试试这个
public JsonResult GetBooks(string context)
{
string rating = context.Split('?')[0];
string[] authors = context.context.Split('?')[1].Split(',');
var books = db.Books.Where(s => authors.Contains(s.AuthorName) && s.Rating == rating);
return Json(books, JsonRequestBehavior.AllowGet);
}
结果发现我使用了错误的URL格式
http://localhost:65239/api/books?context=5?James,Tom
您是否尝试了[HttpGet]属性?
http://localhost:65239/api/books?context=5?James,Tom