views:

108

answers:

2

I'm buiding a UrlHelper for a route as in best practices

the problem is that the returned value is always null when debugging in found that

Url.RouteUrl("x") return null

Url.RouteCollection["X"] return Route

i'm trying to do :

public static string Category(this UrlHelper helper, int Id, string category)
{
     return helper.RouteUrl("X", new {id = Id, category= category});
}

I can't see where I'm doing something wrong

+3  A: 

It appears that this is being caused because you did not specify a default value for {id} and {category} when registering your routes.

Url.RouteUrl("x") will return null because there's no value for id and category provided, and your route definition does not have a default.

I think that you will find if you update your route entry to specify a default value for id and category this will solve your problem. Alternatively, if you are sure to always provide a value for id and category, you can do without it.

As far as your actual Url helper method Category(), that should be working just fine as-is if you are providing a non-null or empty value for id and category. I literally copied the code and it works for me.

Kurt Schindler
A: 

For some reason i was still running the mvc release candidate I installed the mvc 1.0 and now it works fine

freddoo