2
I Mapeed a new route on my site like this:
routes.MapRoute(
"PaymentEdit",
"Payment/{type}",
new { controller = "Contributor", action = "Payment" },
new { type = UrlParameter.Optional }
);
My Action is this:
[AutorizacaoFilterAttribute]
public ActionResult Payment(string rt)
{
Debug.WriteLine(rt);
return View();
}
The controller is called Contributor, it’s right. But when I call the url: http://localhost:54345/Contributor/Payment/1
Debug doesn’t return anything in Output
.
I’ve done the same kind of route in another Action and works normal, in my view is the same thing, follow the code:
Route:
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();
}
When I call the url http://localhost:54345/Home/Image/2107209300
the Debug
me return normally the value 2107209300
I’ve tried it several times in different ways, and I can’t find the difference between the two.
My complete Route.config:
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: Changing the route and inserting it in first place on route.config, when I pass the url: http://localhost:54345/Contributor/Payment/41242 I have the following error:
The type constraint entry on the route with the 'Contributor/Payment/{type}' URL must have a string value or be of a type that implements Irouteconstraint.
Follow the edited route:
routes.MapRoute(
"Contributor",
"Contributor/Payment/{type}",
new { controller = "Contributor", action = "Payment" },
new { type = UrlParameter.Optional }
);
What do you call
views
are, in fact,actions
.– Jéf Bueno
@LINQ Yes, these are the actions
– Leonardo Bonetti
Post your file
RouteConfig.cs
full. Taking advantage, try to put the payment route before the others.– Randrade
It is with certainty shock of routes, post the complete file of
RouteConfig.cs
– novic
Personal edited !
– Leonardo Bonetti
@Leonardobonetti the name route
Home
theprodutoid
is of what type– novic
@Virgilionovic
string
, as well as the type ofContributor
– Leonardo Bonetti