Page Not Found error 404, [Route ("categories/list / {page=1}")] in Asp.Net MVC
Hello, I'm having a problem regarding Route configuration in the Asp.Net MVC. The problem is that I created a test page where on this page I am trying to configure the route features. I set up a page with search with a method to create a url with the search parameter.
Ex:
The number "1" is the parameter being passed, and the PadedList that you create. And search works perfectly and it manages changes the url in Chrome, more when I copy the url and lap in Microsoft Edge appears an error page 404, Page Not Found.
Controller: Categoriescontroller.cs
using PartionView.DAO;
using PartionView.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
namespace PartionView.Controllers
{
public class CategoriasController : Controller
{
#region Carregamentos de páginas
public ActionResult Index()
{
listCat();
listUsers();
return View();
}
/*
O Endereço ficará:
Get - categorias/list/{page}
*/
[Route("Catetorias/list/{page=1}")]//Para acessar a função
public ActionResult pagteste(int page = 1, int pageSize = 4)
{
listCatPg("", page, pageSize);
return View();
}
[Route("Categorias/list/{pesquisa=}/{page=1}/{pageSize=4}")]
public ActionResult pagteste(string pesquisa = "", int page = 1, int pageSize = 4)
{
listCatPg(pesquisa, page, pageSize);
return View();
}
#endregion
//===================================================================================
#region Metodos Usados
/// <summary>
/// Método usado para lista todas as categórias.
/// </summary>
/// <param name="Pesquisa">Recebe a categoria para pesquisa.</param>
/// <returns>Retorna lista na ViewBag de categorias.</returns>
public ActionResult listCat(string Pesquisa = "")
{
var dao = new CategoriaDao();
var list = dao.listaCategoria(Pesquisa);
if (Request.IsAjaxRequest())
{
return PartialView("_PvCategorias", list);
}
ViewBag.cat = list;
return View();
}
/// <summary>
/// Método usado para lista todas as categórias.
/// </summary>
/// <param name="Pesquisa">Recebe a categoria para pesquisa.</param>
/// <returns>Retorna lista na ViewBag de categorias.</returns>
[HttpGet]
public ActionResult listCatPg(string pesquisa = "", int page = 1, int pageSize = 4)
{
var dao = new CategoriaDao();
var list = dao.listaCategoria(pesquisa);
PagedList<Categoria> pl = new PagedList<Categoria>(list, page, pageSize);
PesquisaFiltro pf = new PesquisaFiltro
{
categorias = pl,
pesquisa = pesquisa,
page = page,
pageSize = pageSize
};
ViewBag.pf = pf;
if (Request.IsAjaxRequest())
{
return PartialView("_PvPagteste", pf);
}
ViewBag.cat = pf;
return View(pf);
}
/// <summary>
/// Método usado para lista todas as usuários.
/// </summary>
/// <param name="Pesquisa">Recebe a usuário para pesquisa.</param>
/// <returns>Retorna lista na ViewBag de usuários.</returns>
public ActionResult listUsers(string PesquisaUsers = "")
{
var dao = new CategoriaDao();
var list = dao.listaUsuarios(PesquisaUsers);
if (Request.IsAjaxRequest())
{
return PartialView("_PvUsuarios", list);
}
ViewBag.us = list;
return View();
}
#endregion
}
}
Not RoutConfig.cs and the default, I only added MapMvcAttributeRoutes().
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//Para mapear os atributos das rotas direto no controller.
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Things I noticed doing tests:
- if you run the index page, and I put the url ' http://localhost:59180/catetorias/list/1 " already passing the parameter 1, 2 or 3 it does not work.
- doesn't work either if you copy the url above and paste it into another browser.
If anyone knows it would be a good help.
1
Author: Fabiano Gonzaga, 2019-07-02
1 answers
I already found out, it was just a typo:
[Route("Catetorias/list/{page=1}")]
-1
Author: Fabiano Gonzaga, 2019-07-04 03:47:15