0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.