mvc como mudar a rota padrão
Eu estou passando pelo livro de framework Pro Asp.net mvc3. Eu quero mudar a rota padrão para que eu possa ter uma home page diferente. Eu adicionei um novo controlador chamado Pages e uma visão chamada Home. Isto é o que eu estou querendo como minha home page.
Eu tentei adicionar isso ao meu global.asax.cs
routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
new { controller = "Pages", action = "Home", id = "DefautId" });
Isso muda a página padrão, mas estraga as categorias
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(null,
"", // Only matches the empty URL (i.e. /)
new
{
controller = "Product",
action = "List",
category = (string) null,
page = 1
}
);
routes.MapRoute(null,
"Page{page}", // Matches /Page2, /Page123, but not /PageXYZ
new {controller = "Product", action = "List", category = (string) null},
new {page = @"\d+"} // Constraints: page must be numerical
);
routes.MapRoute(null,
"{category}", // Matches /Football or /AnythingWithNoSlash
new {controller = "Product", action = "List", page = 1}
);
routes.MapRoute(null,
"{category}/Page{page}", // Matches /Football/Page567
new {controller = "Product", action = "List"}, // Defaults
new {page = @"\d+"} // Constraints: page must be numerical
);
routes.MapRoute(null, "{controller}/{action}");
}
O que devo fazer para que isso funcione?
ATUALIZAR:
URLS:Página inicial vai para a lista de itens
http://localhost/SportsStore/
categoria clicada
http://localhost/SportsStore/Chess?contoller=Product
Controlador que é atingido para a home page
public class ProductController : Controller
{
private readonly IProductRepository repository;
public int PageSize = 4;
public ProductController(IProductRepository repoParam)
{
repository = repoParam;
}
public ViewResult List(string category, int page = 1)
{
var viewModel = new ProductsListViewModel
{
Products = repository.Products
.Where(p => category == null || p.Category == category)
.OrderBy(p => p.ProductID)
.Skip((page - 1)*PageSize)
.Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = page,
ItemsPerPage = PageSize,
TotalItems = category == null
? repository.Products.Count()
: repository.Products.Where(
e => e.Category == category).Count()
},
CurrentCategory = category
};
return View(viewModel);
}
Controlador que eu estou querendo ser atingido para a home page
public class PagesController : Controller
{
public ViewResult Home()
{
return View();
}
}
obrigado,