내 WebApiConfig.cs라우팅 이상하게
행동내 컨트롤러 파일은 다음과 같습니다 51,255/API/계정/XGetUsers 내가 400 오류가 계속 :
namespace myApp.Data
{
public class AccountController : ApiController
{
public List<User> XGetUsers()
{
List<User> Users;
using (Entities db = new Entities())
{
var users = from u in db.Users select u;
Users = users.ToList();
}
return Users;
}
// GET api/<controller>/5
public string Get(int id)
{
return "value";
}
}
}
하지만 로컬 호스트를 호출하려고 할 때마다 :
{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in myApp.Data.AccountController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
모든 호출이 Get (int id) 메서드로가는 것 같습니다. 뭐가 잘못 되었 니?
routeTemplate: "api/{controller}/{action}/{id}",
은 그래서
{id}
이
XGetUsers
이라고 생각했다 :
@OldGeezer, 걱정할 필요가 없습니다. 도움이 될 수있어서 기쁩니다! –