Eu mapeei uma nova rota no meu site assim:
routes.MapRoute(
"PaymentEdit",
"Payment/{type}",
new { controller = "Contributor", action = "Payment" },
new { type = UrlParameter.Optional }
);
Minha Action é essa:
[AutorizacaoFilterAttribute]
public ActionResult Payment(string rt)
{
Debug.WriteLine(rt);
return View();
}
O controller se chama Contributor, está certinho. Porém quando eu chamo a url: http://localhost:54345/Contributor/Payment/1
o ´Debug´ não me retorna nada no Output
.
Já fiz o mesmo tipo de rota em outra Action e funciona normal, ao meu ver está a mesma coisa, segue o código:
Rota:
routes.MapRoute(
"Home",
"Image/{produtoid}",
new { controller = "Home", action = "Image"},
new { produtoid = UrlParameter.Optional }
);
Action:
public ActionResult Image(string id)
{
Debug.WriteLine(id);
return View();
}
Quando eu chamo a url http://localhost:54345/Home/Image/2107209300
o Debug
me retorna normalmente o valor 2107209300
Eu já testei diversas vezes de diversos modos, e não consigo encontrar a diferença entre as duas.
Meu Route.config completo:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace SiteTeste
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"Home",
"Image/{produtoid}",
new { controller = "Home", action = "Image"},
new { produtoid = UrlParameter.Optional }
);
routes.MapRoute(
"Contributor",
"Payment/{type}",
new { controller = "Contributor", action = "Payment" },
new { type = UrlParameter.Optional }
);
}
}
}
EDIT: Alterando a rota e inserindo ela em primeiro lugar no route.config, quando passo a url: http://localhost:54345/Contributor/Payment/41242 tenho o seguinte erro:
A entrada de restrição 'type' na rota com a URL 'Contributor/Payment/{type}' deve ter um valor de cadeia de caracteres ou ser de um tipo que implementa IRouteConstraint.
Segue a rota editada:
routes.MapRoute(
"Contributor",
"Contributor/Payment/{type}",
new { controller = "Contributor", action = "Payment" },
new { type = UrlParameter.Optional }
);
views
são, na verdade,actions
.RouteConfig.cs
completo. Aproveitando, tente colocar a rota do pagamento antes das outras.RouteConfig.cs