'How to query an array of integers in an integer collection in ASP.NET Core 3.1?
I would like to query an integer collection. For now, I can only filter by the first value in the array of integers. How can I query that includes all values in the integer array for a blog tag id collection?
//list --> my blog posts variable
....
if (f.blogTagIds != null)
{
list = list.Where(p => p.BlogTagRelation.Select(p => p.BlogTagId).Contains(f.blogTagIds[0]));
}
....
SearchFilterClass
public class SearchFilterType
{
...
public int[] blogTagIds { get; set; }
...
}
ViewBag BlogTags
var BlogTags = new List<SelectListItem>();
foreach (var item in _uow.BlogTag.GetAllByEnabledDate(null, _uow.Cookie.GetAdminLangId, _uow.Cookie.GetAdminWebSiteId))
{
BlogTags.Add(new SelectListItem
{
Text = item.Title,
Value = item.Id.ToString()
});
}
ViewBag.BlogTags = BlogTags;
Filter Form BlogTagIds Select Control
<select asp-for="f.blogTagIds" class="form-control" multiple="multiple" asp-items="ViewBag.BlogTags"></select>
BlogTagRelation.cs
public partial class BlogTagRelation
{
public int Id { get; set; }
public int BlogId { get; set; }
public int BlogTagId { get; set; }
public virtual Blog Blog { get; set; }
public virtual BlogTag BlogTag { get; set; }
}
Example route
/Blog/list?f.blogTagIds=8&f.blogTagIds=6
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
