<select asp-for="Colors" asp-items="@Model.Colors_SELECT " class="MultiSelect" multiple> .... </select>
[BindProperty(SupportsGet = true)] public List<string>? Colors { get; set; } public SelectList? Colors_SELECT { get; set; } public async Task<IActionResult> OnPostAsync() { var CurrentFilters = new Dictionary<string, string>(); var ColorsTemp = string.Join(",", Colors); CurrentFilters.Add("Colors", ColorsTemp); string query = ""; foreach (var p in CurrentFilters) { query += $"{p.Key}={p.Value}&"; } query = query.TrimEnd(query[query.Length - 1]); //remove last '&' var url = $"{HttpContext.Request.Path}?{query}"; // create URL return Redirect(url); // Send new url } public async Task OnGetAsync() { string result = Request.Query["Colors"]; if (!string.IsNullOrEmpty(result)) { string[] TempArray = result.Split(","); for (int i = 0; i < TempArray.Length; i++) { Colors.Add(TempArray[i]); } } }
public async Task OnGetAsync() { - Colors.Add("Black"); string result = Request.Query["Colors"]; if (!string.IsNullOrEmpty(result)) { string[] TempArray = result.Split(","); for (int i = 0; i < TempArray.Length; i++) { //Colors.Add(TempArray[i]); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)