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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:51:02+00:00 2026-06-05T22:51:02+00:00

I have page where I use model which can have different types (depending by

  • 0

I have page where I use model which can have different types (depending by action and controller). My problem starts when I want to use partial which take parameter from Model like:

@Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field1))

but, if I not declare type of model I have an error like Partial can not use dynamic values. So I have idea to solve it with:

@if (Model.GetType() == typeof(ContentPage))
{
    @model ContentPage
    @Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field1))
}
else if (Model.GetType() == typeof(Data.Models.Directory))
{
    @model Directories
    @Html.Partial("~/Views/Components/SubMenu.cshtml", MyProject.Web.MenuHelper.GetSubMenu(Model.field2))
}

But then I have error like: ContentPage.field2 no exist.

Do you have any ideas how can I solve it?

Any help would be appreciated.

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

    It’s not a good idea to strongly type a view or a partial view with different models based upon conditions. If you still want to use different kind of models in a view/partial view then you have to go for ViewData/ViewBag approach.

    The other option is you can go for generic view models see this thread.

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

Sidebar

Related Questions

I have a page that requires jQuery.tmpl, but I want to use native knockout
I am writing ruby on rails application, which will have 2 different users types
I have two views which will both use the same Controller method: //webServiceController.cs //The
I have a page layout that I use in my SharePoint solution when I
I have a web page that I use to update a fairly complex data
Assume you have a page in ASP.NET where it makes sense to use JavaScript/jQuery
I have an link in HTML and I use Page Object pattern to write
I have a page with joomla and Chronoforms on it. How do i use
I have a page with photo gallery http://dev.dolina-imeniy.ru/fotogalereya/kp_usadba_tishnevo/ I use this to bind click
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity

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.