How to redirect a query string using ?? and how to handle it

In my global asax file, I want to map a route, for example:

http://domain.com/add/link?url=http%3A%2F%2Fgoogle.com 

And then catch it with my LinkController with the Add action.

I'm doing it?

global.asax →

 routes.MapRoute( "AddLink", "Add/Link?{url}", new { controller = "Link", action = "Add" } ); 

LinkController →

 public string Add(string url) { return url; // just want to output it to the webpage for testing } 

?? This does not work. What am I doing wrong? Thanks!

+7
asp.net-mvc asp.net-mvc-2
source share
2 answers

ASP.Net MVC will automatically bind parameters from the query string; you do not need to point it on the route.

Your route may just be

 routes.MapRoute( "AddLink", "Add/Link", new { controller = "Link", action = "Add" } ); 
+15
source share

Show mvc SourceProviderFactories source code.

 namespace System.Web.Mvc { using System; public static class ValueProviderFactories { private static readonly ValueProviderFactoryCollection _factories = new ValueProviderFactoryCollection() { new FormValueProviderFactory(), new RouteDataValueProviderFactory(), new QueryStringValueProviderFactory(), new HttpFileCollectionValueProviderFactory() }; public static ValueProviderFactoryCollection Factories { get { return _factories; } } } } 
0
source share

All Articles