Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1838096
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:26:08+00:00 2026-05-17T06:26:08+00:00

It appears that in C# 4.0, variance specifiers are only applicable to interface types.

  • 0

It appears that in C# 4.0, variance specifiers are only applicable to interface types.

So let’s say I have ViewModel / EditModel classes and a simple hierarchy of models.

class MyEditModel<T> where T : Base { ... }
class Derived1 : Base { ... }
class Derived2 : Base { ... }

I have a partial view that accepts a MyEditModel of any type (so long as it’s derived from Base) and another one that only accepts instances of Derived1. Now how do I render both on the same page?

The partial view that accepts any MyEditModel will be shared between the editor for Derived1 and the editor for Derived2.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T06:26:09+00:00Added an answer on May 17, 2026 at 6:26 am

    The only has you could do this is if your view accept a view model of Base. From an OO perspective MyEditModel and Derived1 share Base as the common base class – but they don’t share anything else – there is no other relationship. Hence, if you’re trying to use the same then it would have to derive from Base. Presumably the properties on Base are the only ones they have in common.

    Edit:
    I mis-interpreted the original question. Based on the literal text of your question, I thought you were passing Derived1 but base on your comment below you are passing MyEditModel<Derived1>. This will do what you’re seeking:

    Inherits="System.Web.Mvc.ViewPage<dynamic> 
    

    You don’t get the benefit of intellisense with dynamic – but you do get the benefit of reusing the same view file for your types and the benefit of not having to create extra view model classes just to make the compiler happy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it appears that the Apple site now only provides download for Xcode 3.2, that
It appears that we will have to build/deploy one of our new JBoss apps
It appears that ViewDidLoad() is sent to a ViewController only after its View is
It appears that to use Google Translate you have to use an API key
So in Sql Server it appears that I cannot have specific steps within my
It appears that all the touch methods of a UIView are only called if
It appears that on Windows 7 Cygwin/vim thinks all files are read only. You
On the surface it appears that python uses json natively. The only exception I
It appears that side-swipe menus are becoming a more common interface element as more
It appears that we have access to Rails.logger and logger inside Rails applications. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.