Argumentoutofrangeexception: индекс был вне диапазона. Должно быть неотрицательным и меньше размера коллекции
I'm using mvc core And I ran into a problem here is my code
public async Task<IActionResult> Index(string filter, int page = 1, string sortExpression = "product") { List<String> arr = new List<string>(); var qry = _context.Model.Where(op => op.Type == "Laptops").AsQueryable(); int i = 0; if (!string.IsNullOrWhiteSpace(filter)) { string[] parts = filter.Split(','); foreach (var item in parts) { arr.Add(item); } while (i<=arr.Count) { qry = qry.Where(op => op.product.Contains(arr[i])); i++; } var model = await PagingList.CreateAsync( qry , 12, page, sortExpression, "product"); model.RouteValue = new RouteValueDictionary { { "filter", filter} }; return View("Index", model); } //var model = await PagingList.CreateAsync( // qry, 12, page, sortExpression, "product"); //model.RouteValue = new RouteValueDictionary { // { "filter", filter} //}; return View(); } }
Что я уже пробовал:
An unhandled exception occurred while processing the request. ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.ThrowHelper.ThrowArgumentOutOfRange_IndexException() InvalidOperationException: An exception was thrown while attempting to evaluate a LINQ query parameter expression. To show additional information call EnableSensitiveDataLogging() when overriding DbContext.OnConfiguring. Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.ParameterExtractingExpressionVisitor.Evaluate(Expression expression, out string parameterName)