【发布时间】:2014-09-26 10:09:00
【问题描述】:
我的 WebAPI 项目包含以下控制器。
public class StateController : ApiController
{
// GET: api/State
public IEnumerable<State> Get()
{
return new StateRepository().GetAll();
}
////////////// How to call this method from client code ? //////////////
public IEnumerable<State> GetAllByCountryId(int id)
{
return new StateRepository().GetAllStatesByCountryId((short)id);
}
// GET: api/State/5
public State Get(int id)
{
return new StateRepository().Get(id);
}
// POST: api/State
public void Post([FromBody]State state)
{
new StateRepository().Create(state);
}
// PUT: api/State/5
public void Put(int id, [FromBody]State state)
{
new StateRepository().Update(state);
}
// DELETE: api/State/5
public void Delete(int id)
{
new StateRepository().Delete(id);
}
}
【问题讨论】:
-
你想从
IEnumerable<State> Get()方法调用这个方法-GetAllByCountryId(int id)对吗???
标签: c# asp.net .net asp.net-mvc asp.net-web-api