2013-11-03 2 views
3

내 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이라고 생각했다 :

답변

4

귀하의 경로는 작업이 없습니다.

+0

@OldGeezer, 걱정할 필요가 없습니다. 도움이 될 수있어서 기쁩니다! –

1

하나의 가능성 만 정의한 것처럼 보입니다. 컨트롤러 뒤의 부분은 ID입니다. 이 작업과 일치하는 작업은 하나뿐이므로 해당 작업 만 호출 할 수 있습니다.

아마도 다른 후보와 일치하도록 "api/{controller}/{action}/{id}"을 추가하고 싶을 것입니다.