无法获取odata请求参数和值

时间:2018-03-14 20:48:39

标签: asp.net-web-api asp.net-web-api2 odata

我有一个webapi 2项目。我在下面调用fetch参数和指定的值,但RouteData为空。

 var routeData = HttpContext.Current.Request.RequestContext.RouteData;
 var id = routeData.Values["contextId"] as string;

这是网址:http://localhost:29016/api/v1/Contexts(1)/Applications

并且路由设置如下,

        // OData routing.
    _configuration.MapODataServiceRoute(
            "ODataRoute",
            "api/v1/Contexts({contextId})",
            GetModel(_configuration));

在调用Controller操作之前,我需要contextId参数值。我已经确认HttpContext.Current.Request.RequestContext引用了正确的请求。

0 个答案:

没有答案
相关问题