Answer the question
In order to leave comments, you need to log in
Can't implicitly convert type "string"?
There was a simple request to extract a list in descending order from the database with pagination and search on the page:
public async Task<IActionResult> Online(string name, int page = 1)
{
int pageSize = 30; // количество элементов на странице
IQueryable<Chr> source = from c in db.Chr
orderby c.RCount, c.Level
select new Chr()
{
Name = c.Name,
};
if (!String.IsNullOrEmpty(name))
{
source = source.Where(p => p.Name.Contains(name));
}
var count = await source.CountAsync();
var items = await source.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
// формируем модель представления
IndexViewModel model = new IndexViewModel
{
PageViewModel = new PageViewModel(count, page, pageSize),
FilterViewModel = new FilterViewModel(db.Chr.ToList(), name),
Chr = items
};
return View(model);
}
public class IndexViewModel
{
public IEnumerable<Chr> Chr { get; set; }
public PageViewModel PageViewModel { get; set; }
public FilterViewModel FilterViewModel { get; set; }
}
public async Task<IActionResult> Online(string name, int page = 1)
{
int pageSize = 30; // количество элементов на странице
IQueryable<Chr> source = from c in db.Chr
join g in db.GMember
on c.Name equals g.Name into gg
from ggg in gg.DefaultIfEmpty()
orderby c.RCount, c.Level
select new IndexViewModel()
{
Chr = c.Name,
GMember = ggg.G_Name
};
if (!String.IsNullOrEmpty(name))
{
source = source.Where(p => p.Name.Contains(name));
}
var count = await source.CountAsync();
var items = await source.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync();
// формируем модель представления
IndexViewModel model = new IndexViewModel
{
PageViewModel = new PageViewModel(count, page, pageSize),
FilterViewModel = new FilterViewModel(db.Chr.ToList(), name),
Chr = items
};
return View(model);
}
Не удается неявно преобразовать тип "string" в "System.Collections.Generic.IEnumerable<Web.Models.DataBase.Chr>"
Не удается неявно преобразовать тип "string" в "System.Collections.Generic.IEnumerable<Web.Models.GMember>"
Chr = c.Name,
GMember = ggg.G_Name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question