MVC4 アプリケーションがあり、次のようなテスト webapi ベースのコントローラーを作成しました。
public class User1
{
public int Id { get; set; }
public string name { get; set; }
public User1(int id, string name)
{
this.Id = id;
this.name = name;
}
}
public class Test1Controller : ApiController
{
public User1 Get(int id)
{
return new User1(id, "hello");
}
}
webapiconfig クラスがあることに気付きました。
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
これはデフォルトでjsonの結果が正しいと思いますか?
私が行くとき:
http://localhost:61146/api/test1/get/1
また
http://localhost:61146/test1/get/1
次のエラーが表示されます。
The resource cannot be found.
これはどのように正確にマップされますか、または特別なフォルダーにドロップする必要がありますか? ApiController から継承しているので、それ自体でマップされると思います