Using a generic model in ASP.NET MVC Razor

前端 未结 5 1768
刺人心
刺人心 2020-12-29 01:15

Is it possible to use a generic model in ASP.NET MVC 3 (w/ Razor)? The following fails with a syntax error:

@model DtoViewModel where T : IDto
         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 01:41

    given that @model is expecting a type - not a type declaration you could use:

    @model DtoViewModel
    

    and take advantage of generic covariance

提交回复
热议问题