我这里有一个函数,该函数将进行ajax调用以返回数据。我想使用所示的5个变量返回数据以过滤数据。
工作区,司法管辖区和标签将来自查询字符串,其格式如下:
details?companyid = 1&datepreset =上个月&jurisdictionref = 3&jurisdictionref = 6&jurisdictionref = 18&s = 1&workarearef = 2&workarearef = 11&workarearef = 14
datapreset
和companyid
来自有效的视图。
如何将查询字符串解析为ajax调用,然后我想使用linq来过滤带有url中引用的结果?
JS:
taxiBriefingShow.click(function (e) {
e.preventDefault();
if (!loaded) {
var companyId = $(this).data('companyid');
var workAreaRefs = // from querystring, 0 to many: workarearef=1&workarea=2&workarea=99 etc
var jurisdictions = $(this).data("jurisdictions"); // from querystring, 0 to many: jurisdiction=1&jurisdiction=2&jurisdiction=99 etc
var tags = $(this).data("tags"); // from querystring, 0 to many: tagref=1&tagref2=2&tagref=99 etc
var preset = $(this).data("preset");
var filterModel =
{
WorkareaRefs: workAreaRefs,
Jurisidctions: jurisdictions,
Tags: tags,
Preset: preset
}
$.ajax({
data: JSON.stringify(filterModel),
url: '/api/track/v1/taxibriefing?companyId=' + companyId + '&preset=' + preset + '&workarearefs=' + workAreaRefs + '&tags=' + tags + '&jurisdictions=' + jurisdictions,
async: false,
success: generateTaxiLists
});
}
togglePanel();
});
我正在使用模型中应用的以下过滤器设置属性:
public IList<TrackFilterGenericRef> Workareas { get; set; }
public IList<TrackFilterGenericRef> Jurisdictions { get; set; }
public IList<TrackFilterGenericRef> Tags { get; set; }
要在API控制器中设置以下属性:
var workareas = workareaRefs.Split(',')
中的部分有误。
[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);
}
}
工作区,管辖区和标记应包含来自名为r
的变量中存储的查询字符串的workareaRefs / jurisdictions / tags中的值。
谁能帮我实现这一目标?