views:

290

answers:

1

I am a big fan of optional parameters in C#4 but am having an issue with MVC when I use them in my controller constructors. For example, if I have a single constructor:

public TestController(sting a = "") { /* blah */ }

MVC has a fit saying that there are no parameterless constructors for TestController.

How can I get around this?

+1  A: 

The MVC error message is correct - there are no parameterless constructors. You need to provide a parameterless constructor (which in your case should just delegate to the parameterful constructors). Optionally, if you're using DI, there are controller factories which are explicitly designed to inject the dependencies into the constructor. I believe MvcContrib has a few of these.

Levi