views:

59

answers:

1

I'm running into an error with T4MVC and named parameters. I have a controller:

public class ProductsController : Controller
{
    public virtual ViewResult List(int page = 1)
    {
        // foo.DoSomething()
    }
}

It seems T4MVC creates an overload List() as well. The result is that calling

myProductsController.List(3)

correctly executes foo.DoSomething(). But calling

myProductsController.List()

does NOT execute foo.DoSomething() - T4MVC created an empty List() overload.

I've taken T4MVC out of my project, and everything works fine now. But I'd really like to be able to use it - am I missing a setting somewhere?

+2  A: 

UPDATE: Ok, I have a real fix now. It's checked into the Codeplex repository. You can get the latest T4MVC.tt by going to here. Before I include that in the next official build, it would be great if you could try it and confirm that it works for you. Thanks!


You're right, there is a problem here. I had not run into this situation before. For a short term quick fix, just get rid of the following code from T4MVC.tt (around line 370):

<#foreach (var method in controller.ActionMethodsUniqueWithoutParameterlessOverload) { #>
        [NonAction]
        [<#= GeneratedCode #>, DebuggerNonUserCode]
        public <#=method.ReturnTypeFullName #> <#=method.Name #>() {
            return new T4MVC_<#=method.ReturnType #>(Area, Name, ActionNames.<#=method.ActionName #>);
        }
<#} #>

But I'll need to look for a real fix. Normally, this generation happens when the action has no no-param overload. It just needs to detect that an action with all-optional params should basically be treated as a no-param case.

David Ebbo
It works - thank you for the lightning-quick fix!!!!
Gabriel Florit
Great, that fix will be in 2.6.22, whenever I get to push a new build out.
David Ebbo