Url.Action() helper with T4MVC action call optional parameters

May 30, 2012 at 4:16 PM

With the following action signature: 

public virtual ActionResult JsonFeed(int day = 0, int month = 0, int year = 0, string culture = "") {}

and the following route:

culture = WebSettings.Instance.DefaultCulture,
controller = "Post",
action = "JsonFeed",
day = UrlParameter.Optional,
month = UrlParameter.Optional,
year = UrlParameter.Optional

T4MVC will create an URL like "/culture/posts/json/0/0/0" when calling :


This is something we don't really want. ASP.NET MVC is able to handle the "URL /culture/posts/json" just fine. Actually, the ASP.NET MVC built in Url.Action(action, controller) will skip the optional parameters.

Is there a way we put a setting in the settings file to set the behaviour when optional parameters are present in controller actions?

May 31, 2012 at 8:26 PM

Normally, T4MVC generates a no-param action overload that would make this work. But in this case, it can't do this because all the action params are already optional.

And then once it calls the regular overload, it ends up putting all the values in the route.

I need to think about the situation some more.