Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 14, 2008 03:22 AM by andrebtoda
0 Points
4 Posts
May 14, 2008 02:21 AM|LINK
Hello friends!
What is wrong if my code?
Global.asax.cs
public class GlobalApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { // Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable // automatic support on IIS6 and IIS7 classic mode routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { action = "Index", id = "" }), }); routes.Add(new Route("Default.aspx", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }), }); routes.Add(new Route("Busca/BuscaSimples/{entrada}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Busca", action = "BuscaSimples", entrada = "" }), }); }
And my the BuscaSimples at BuscaController.cs
public void BuscaSimples(string entrada) { List listaEntradas = dicionarioM.GetVerbeteByEntrada(entrada); RenderView("Busca", listaEntradas); }
Ok, but when i go to http://www.mysite.com/Busca/BuscaSimples/test/
i got the param entrada is null and not "test"
what is wrong?
MVC Controller routing route
Star
13403 Points
2531 Posts
May 14, 2008 03:06 AM|LINK
Hi,
Your url is triggering the first route. It's best to have specific routes prior to more general routes because of the way matching is done. The solution should be easy enough, just cut lines 8 to 11 out and paste them between lines 22 and 23.
You might like to check out Phil Haack's route debugger at http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Good luck
May 14, 2008 03:22 AM|LINK
Thats work fine!
Thank you my friend! [Yes]
andrebtoda
0 Points
4 Posts
Routing problem...doesnt work
May 14, 2008 02:21 AM|LINK
Hello friends!
What is wrong if my code?
Global.asax.cs
public class GlobalApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { // Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable // automatic support on IIS6 and IIS7 classic mode routes.Add(new Route("{controller}/{action}/{id}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { action = "Index", id = "" }), }); routes.Add(new Route("Default.aspx", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", id = "" }), }); routes.Add(new Route("Busca/BuscaSimples/{entrada}", new MvcRouteHandler()) { Defaults = new RouteValueDictionary(new { controller = "Busca", action = "BuscaSimples", entrada = "" }), }); }And my the BuscaSimples at BuscaController.cs
Ok, but when i go to http://www.mysite.com/Busca/BuscaSimples/test/
i got the param entrada is null and not "test"
what is wrong?
MVC Controller routing route
Paul Linton
Star
13403 Points
2531 Posts
Re: Routing problem...doesnt work
May 14, 2008 03:06 AM|LINK
Hi,
Your url is triggering the first route. It's best to have specific routes prior to more general routes because of the way matching is done. The solution should be easy enough, just cut lines 8 to 11 out and paste them between lines 22 and 23.
You might like to check out Phil Haack's route debugger at http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx
Good luck
andrebtoda
0 Points
4 Posts
Re: Routing problem...doesnt work
May 14, 2008 03:22 AM|LINK
Thats work fine!
Thank you my friend! [Yes]