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 8339017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:46:07+00:00 2026-06-09T04:46:07+00:00

I have very simple question that I cannot find the answer to. In the

  • 0

I have very simple question that I cannot find the answer to.
In the razor view there’s a Model of interface type. That interface have multiple subclasses implementing it.
The question is: How can I cast the model to its actual type?
I MUST have variable of actual type but don’t know how to get it from the reflection
I.E.

@model IInterface
@{
   var actualType1 = Model as Model.GetType(); // doesn't work :(
   var actualType2 = (Model.GetType()) Model; // doesn't work :(
}

As you can imagine I am not interested in Model as ActualType or (ActualType) Model because I don’t know what actual type is coming in advance. Its a question about the technique rather than architecture.

Thanks in advance!

  • 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-06-09T04:46:08+00:00Added an answer on June 9, 2026 at 4:46 am

    You are really on the wrong path here. You can’t really do what you’re looking to do here, because you are not really thinking it through. A statement like this:

    var actualType1 = Model as Model.GetType(); 
    

    Won’t work because var is not a dynamic type, it’s a static type that is typed at compile time, not at runtime. So even if you could somehow manage to get it to work, it would only work for one type, ever (until it was recompiled again).

    In addition to that, interfaces are a poor choice for this, because interface attributes are seperate from implementation attributes. So regardless of what attributes you have on your classes, you will not get them via an interface to that class.

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

Sidebar

Related Questions

I have a question that is probably very simple, but I cannot find an
I have a very simple question but cannot find a simple answer. I have
I have a really simple question that I cannot find a straightforward answer for.
I have a question that's so simple I cannot believe I can't answer it
I have a very simple question. I have a program that accepts an integer
I have a very simple question for which I can't seem to find an
Hopefully a question with a very simple answer, but it's not one that I've
it is a very simple question that I'm not finding an answer for it.
I have a very simple question, How can I get the POST values from
I have a very simple question. In FB tutorial https://developers.facebook.com/docs/mobile/ios/build/ it starts to login

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.