我正在关注本教程:
并查看“获取图书详细信息”部分。
我看到这段代码:
[HttpGet("api/books/{id}/details")]
public BookDetailDto GetBookDetail(int id)
{
}
但是我收到的错误是
HttpGet 有 0 个参数,但使用 1 个参数调用
(我在 ASP .net 4.0 WebAPI 上)
指定路线的 /details 部分的新方法是什么?
我的核桃:
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers.Core" version="1.2" targetFramework="net40" />
<package id="Microsoft.AspNet.Providers.LocalDB" version="1.1" targetFramework="net40" />
<package id="Microsoft.AspNet.Razor" version="2.0.20715.0" targetFramework="net40" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="4.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.OData" version="4.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.Tracing" version="4.0.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net40" />
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
尝试升级到 WEBAPI 的 beta 版本
update-Package : Could not install package 'Microsoft.AspNet.WebApi.Client 5.0.0-beta2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files
that are compatible with that framework. For more information, contact the package author.
Update-Package : Updating 'Microsoft.AspNet.Mvc 4.0.30506.0' to 'Microsoft.AspNet.Mvc 5.0.0-beta2' failed. Unable to find a version of 'Microsoft.AspNet.Mvc.FixedDisplayModes' that is compatible with 'Microsoft.AspNet.Mvc 5.0.0-beta2'.
Update-Package : Updating 'Microsoft.AspNet.Mvc 4.0.30506.0' to 'Microsoft.AspNet.Mvc 5.0.0-beta2' failed. Unable to find a version of 'Microsoft.AspNet.Mvc.FixedDisplayModes' that is compatible with 'Microsoft.AspNet.Mvc 5.0.0-beta2'.
通过重新定位到 4.5 并删除 FixedDisplayModes 包来修复这些问题