I really want to do this…
public class BaseController<T> where T : IPageModel, Controller
But visual studio doesnt like it. Controller is a class from the MVC. and I page model ensures acess to some model stuff. Have I got the syntax wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The correct syntax would be:
Everything that follows the
wherekeyword is considered as generic constraint declaration. In your case you want to have your class derive fromController, so you start by indicating this first and at the end you specify the generic constraints.Now your actual controllers could derive from this base controller:
where obviously
Foomust implementIPageModelwhich is enforced by the generic constraint: