C# 分析JS中的查询字符串以筛选结果

C# 分析JS中的查询字符串以筛选结果,c#,ajax,api,filter,call,C#,Ajax,Api,Filter,Call,我这里有一个函数,它将调用ajax返回数据。我想使用5个变量返回数据,如图所示,以过滤数据 WorkAreaRef、jurisidcitons和标记将来自以下格式的查询字符串: 详细信息?公司ID=1&datepreset=lastmonth&JudictionRef=3&JudictionRef=6&JudictionRef=18&s=1&workarearef=2&workarearef=11&workarearef=14 datapreset和companyid来自一个有效的视图 如何将查

我这里有一个函数,它将调用ajax返回数据。我想使用5个变量返回数据,如图所示,以过滤数据

WorkAreaRef、jurisidcitons和标记将来自以下格式的查询字符串:

详细信息?公司ID=1&datepreset=lastmonth&JudictionRef=3&JudictionRef=6&JudictionRef=18&s=1&workarearef=2&workarearef=11&workarearef=14

datapreset
companyid
来自一个有效的视图

如何将查询字符串解析为ajax调用?然后,我想使用linq使用url中的refs过滤结果

JS:

我正在使用模型中应用的过滤器设置这些属性:

    public IList<TrackFilterGenericRef> Workareas { get; set; }

    public IList<TrackFilterGenericRef> Jurisdictions { get; set; }

    public IList<TrackFilterGenericRef> Tags { get; set; }
工作区、辖区和标记应包含名为
r
的变量中存储的查询字符串中workareaRefs/辖区/标记中的值。
有人能帮我做到这一点吗

你在用MVC吗?如果是这样,发布你的控制器方法。使用API控制器,我添加了感谢你的标题和你的标签并不匹配。如果您试图在JS中解析查询字符串,那么之前已经提出过这个问题:。但是您没有
javascript
标记,因此我们是否应该假设您确实希望从API方法中的查询字符串中获取项目?如果是这样,则有一个
[FromQueryString]
属性可以应用于参数。在ajax调用中没有为WorkAreaRef设置数据属性。你已经注释掉了文本。dickrichie抱歉,它现在在里面,谢谢
    public IList<TrackFilterGenericRef> Workareas { get; set; }

    public IList<TrackFilterGenericRef> Jurisdictions { get; set; }

    public IList<TrackFilterGenericRef> Tags { get; set; }
    [HttpPost]
    public async Task<TaxiContainerModel> Post([FromBody] WidgetConfigurationRequestVM data, int companyId, string workareaRefs, string tags, string jurisidctions, DatePreset preset)
    {

        if (!IsCompanyAllowed(data.CompanyId))
        {
            throw new HttpResponseException(HttpStatusCode.Forbidden);
        }

        var MLId = GetMLID(data.CompanyId);
        if (string.IsNullOrWhiteSpace(MLId))
        {
            throw new HttpResponseException(HttpStatusCode.NotFound);
        }

        if (data.Configuration.IsNullOrEmpty())
        {
            throw new HttpResponseException(HttpStatusCode.BadRequest);
        }

        var Workareas = workareaRefs.Split(',');
        var Tags = tags.Split(',');
        var Jurisidctions = jurisidctions.Split(',');

        var r = new TrackDataFilter
        {
            DatePreset = preset,
            Workareas = new List<TrackFilterGenericRef>
            {
                new TrackFilterGenericRef
                {

                    Ref = 2, Type = Enums.ContentTypes.Workarea
                }
            },
        };

        return await taxiBriefingService.GenerateBriefingAsync(data.CompanyId, MLId, data.Notes == null? "" : data.Notes, LexUser.FirmRef, data.Configuration.Select(x=>( x.Row, x.Col, (TaxiWidgetSize)x.Size, (TaxiWidgetType)x.Type)), r);
    }
}