T4MVC OptionParameter value implied from the current context

I noticed that I find it strange behavior with T4MVC. In particular, I am trying to create an ActionLink (using an HtmlHelper) for an action where the optional parameter value is null. This works great most of the time. However, if the current route is the same for which ActionLink is created, and the OptionParameter parameter is nonzero, as a result, ActionLink will indicate the value of the optional parameter from the current route context.

This verbose explanation, I think the code will help clarify.

controller

public virtual ActionResult Today(int? lineNumber = null)
{
    return Index(DateTime.Today, DateTime.Today, lineNumber);
}

Route

context.MapRoute(
    "TodaysProductionSchedules",
    "Production/{Controller}/Today/{lineNumber}",
    new
        {
            area = AreaName,
            controller = MVC.Production.ProductionSchedules.Name,
            action = MVC.Production.ProductionSchedules.ActionNames.Today,
            lineNumber = UrlParameter.Optional
        });

Razor

@Html.ActionLink("Show Today", MVC.Production.ProductionSchedules.Today(null))

, , , . , null ( ), lineNumber .

, ​​T4MVC, codeplx T4MVC. !

+5
1

7/30/2012: T4MVC 2.10.1!

unbinder. t4mvc.tt 639 AddRouteValues ​​ :

    public static void AddRouteValues(RouteValueDictionary routeValueDictionary, string routeName, object routeValue) {
        IModelUnbinder unbinder;
        if (routeValue == null)
        {
            unbinder = DefaultModelUnbinder;
        }
        else
        {
            unbinder = ModelUnbinders.FindUnbinderFor(routeValue.GetType()) ?? DefaultModelUnbinder;
        }
        unbinder.UnbindModel(routeValueDictionary, routeName, routeValue);
    }

: , MVC , , , , (, , ).

, , T4MVC/- , . , , , , .

, MVC, , T4MVC.

PR !:)

+3

All Articles