In asp.net mvc is it possible to make a generic controller?

前端 未结 5 1138
生来不讨喜
生来不讨喜 2020-11-29 01:51

I\'m attempting to create a generic controller, ie:

public class MyController : Controller where T : SomeType
{ ... }

However, whe

5条回答
  •  醉酒成梦
    2020-11-29 02:33

    The default controller factory uses "convention" around controller names when it's trying to find a controller to dispatch the request to. You could override this lookup functionality if you wanted, which could then allow your generic controller to work.

    This MSDN article...

    http://msdn.microsoft.com/en-us/magazine/dd695917.aspx

    ... has a good writeup of what's going on.

提交回复
热议问题