Why are no query parameters being passed to my NancyFX module?

天涯浪子 提交于 2019-11-30 17:57:32

The parameters argument to your lambda contains the route parameters you captured in the in your Get["/query"]. In this case nothing. See @thecodejunkie's comment for an example where there is something.

To get to the query paramters use Request.Query. That's also a dynamic and will contain whatever query parameters was in the request. Like so:

 Get["/query"] = parameters =>
    {
        var rawStart = Request.Query.start;
        var rawEnd = Request.Query.end;
        var metrics = Request.Query.metrics;

        return Response.AsJson(0);
    };

This should work with your tests too.

You can let NancyFx's model binding take care of the url query string.

public class RequestObject 
{
    public string Start { get; set; }
    public string End { get; set; }
    public string Metrics { get; set; }
}

/query?start=2015-09-27&end=2015-10-27&metrics=loadtime

Get["/query"] = x =>
{
    var request = this.Bind<RequestObject>();
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!