public ActionResult Index(string ordenacao, string pesquisa, string tipoPesquisa, int pagina = 1) { int totalRegistros = 20; ViewBag.IdParam = ordenacao == "Id" ? "Id_Desc" : "Id"; ViewBag.NomeParam = ordenacao == "Nome" ? "Nome_Desc" : "Nome"; ViewBag.ordenacaoCorrente = ordenacao; ViewBag.tipoPesquisa = tipoPesquisa; ViewBag.pesquisaCorrente = pesquisa; var animais = repoAnimal.GetAllAnimais(ordenacao, pesquisa, tipoPesquisa); var quantidadeRegistros = animais.Count(); if (!string.IsNullOrEmpty(pesquisa) && quantidadeRegistros > 0) { totalRegistros = quantidadeRegistros; } return(View(animais.ToPagedList(pagina, totalRegistros))); }