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

  • Home
  • SEARCH
  • 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 8991985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:07+00:00 2026-06-15T22:51:07+00:00

I have a submenu I want to display only when certain controllers are used

  • 0

I have a submenu I want to display only when certain controllers are used and a certain model is present. I created a partial and tried to render it in the _Layout.cshtml but I get an error stating model item passed is of type … but this dictionary requires item of type…

I could put the menu in each of my views for the controllers with the right type of model being passed but that seems like the less flexible way.

Currently I am checking if my model is null in the _submenu partial

@if(Model != null)

However, this will let any type of model through and then when it is the wrong type it errors.

I thought the best way would be to specify that my @Html.Partial is only run when certain controllers are used. Or Is there a way to verify the model type so the code doesn’t run if the model passed to the view is incorrect?

  • 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-15T22:51:08+00:00Added an answer on June 15, 2026 at 10:51 pm

    It sounds like you need your model to be dynamic (Check this website for more information on this), then on your view you can just check the type of the model and act accordingly:

    @model dynamic
    
    @{
        ViewBag.Title = "IndexNotStonglyTyped";
    }
    
    <h2>Index Not Stongly Typed</h2>
    
    <p>
    @if(Model is MyType) {
       <span>got myType!</span>
    }
    
    </p>
    

    Note: Original example taken from the website mentioned above.

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

Sidebar

Related Questions

I have created a horizontal menu with a horizontal submenu. Though I want all
I have html with a submenu inside another submenu. What i want is on
I have a WPF submenu that I want to reuse in a few places
I want to make a submenu with jQuery and javascript. I have this html
I have an annoying problem, my li's dont want to display side by side
I have this list menu and I want to display arrows for each of
I have a submenu that list departments. Behind this each department have an action
I have a SubMenu in a ContextMenu which ItemSource is set to a expression
I have a submenu that has all items linked to the same node, but
I have the following code that creates a submenu based on current document. The

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.