GenerateParamsForActionMethods And GenerateParamsAsConstantsForActionMethods

Jan 9, 2014 at 8:44 PM
Hello, I didn't know that the params generated where exclusives (one or other). So I edited the .tt to generate both.

The constans are under ActionParameter class in the controller. You can use it in old style (T4MVC.Controller.ActionParams....) in regular code, or use it on Action attributes in the controller
        [TestAttribute(ActionParameter.EditParams.id)]
        public virtual ActionResult Edit(string id)
        {
        }
Here is the code to change if someone need it (around line 284).
<#if (settings.GenerateParamsForActionMethods){
foreach (var group in controller.UniqueParameterNamesGroupedByActionName) if (group.Any()) { #>
        static readonly ActionParamsClass_<#=group.Key #> s_params_<#=group.Key #> = new ActionParamsClass_<#=group.Key #>();
        [<#= GeneratedCode #>, DebuggerNonUserCode]
        public ActionParamsClass_<#=group.Key #> <#=group.Key + settings.ParamsPropertySuffix #> { get { return s_params_<#=group.Key #>; } }
        [<#= GeneratedCode #>, DebuggerNonUserCode]
        public class ActionParamsClass_<#=group.Key #>
        {
<#foreach (var param in group) { #>
<#  if (settings.UseLowercaseRoutes) { #>
            public readonly string <#=param.Name #> = (<#=param.RouteNameExpression #>).ToLowerInvariant();
<#  } else { #>
            public readonly string <#=param.Name #> = <#=param.RouteNameExpression #>;
<#  }
} #>
        }
<# } #>
<#} #>
<#if (settings.GenerateParamsAsConstantsForActionMethods){ #>

        [<#= GeneratedCode #>, DebuggerNonUserCode]
        public class ActionParameter
        {
<#foreach (var group in controller.UniqueParameterNamesGroupedByActionName) if (group.Any()) { #>
            [<#= GeneratedCode #>, DebuggerNonUserCode]
            public class <#=group.Key + settings.ParamsPropertySuffix#>
            {
<#foreach (var param in group) { #>
<#  if (settings.UseLowercaseRoutes) { #>
                public const string <#=param.Name #> = (<#=param.RouteNameExpression #>).ToLowerInvariant();
<#  } else { #>
                public const string <#=param.Name #> = <#=param.RouteNameExpression #>;
<#  }
} #>
            }
<# } #>
        }
<#} #>
Thanks your for that great template :D