【发布时间】:2016-07-25 12:34:00
【问题描述】:
我有一个如下控制器:
public async Task<IHttpActionResult> MyControllerMethod(string currency = null,
string edition = null,
int? systems = null,
string version = null,
Guid? entitlementid = null)
{
//Code here
}
当我从这个 URL 执行这个控制器时:
http://*:*/MyController/MyControllerMethod/?currency=eur&edition=DSSTANDARD&systems=50&version=6.3/
方法的所有参数的值如下:
currency = eur
edition = DSSTANDARD
systems = 50
version = 6.3
但是如果我做同样的添加最后一个参数:
...&entitlementid=B5630B37-0820-4EB0-8A2A-000C44885590/
然后,前 3 个值具有来自 URL 的值,但 entitlementid 始终是 null。
可能是什么问题?
路由配置
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
【问题讨论】:
-
@KartikeyaKhosla 我根本没有
-
这看起来像一个 WebAPI 调用。你能显示路线配置吗?
-
@Nkosi config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{action}/{id}", 默认值: new { id = RouteParameter.Optional } );
-
如果您尝试将
entitlementId更改为字符串,它仍然为空吗?
标签: c# asp.net-mvc asp.net-web-api controller