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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:56:49+00:00 2026-06-06T14:56:49+00:00

let’s consider two views that use the same layout composed of: A left column

  • 0

let’s consider two views that use the same layout composed of:

  • A left column containing a “body” (which is filled differently by both views)
  • A right column that displays general information (passed via the model)

Instead of defining the right part twice, I wondered if I could create a PartialView to link directly from the layout page.

The problem is that the partial views implicitely inherit their models from the view that is being rendered. And since each view has its own model, I end up with a model type mismatch in the partial view.

From here I see two solutions:

  • I could insert the common part of the view model in the ViewBag. Unfortunately this means that each view that uses this layout has to implement this “convention” but nothing warns the developer about it at compile time…
  • I could use polymorphism to make each view model inherit from the same base class (edit: or interface) that the Partial Views uses. This would work up to a certain extend but would potentially exponentially increase in complexity as soon as I have a second partial view in the same layout.

So here are the questions:

  • Am I right with the assumptions above?
  • Do you see any other possibility?
  • Any return on experience on this?

Thanks a lot,
TB.

  • 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-06T14:56:49+00:00Added an answer on June 6, 2026 at 2:56 pm

    Use an Interface and implement it on the two models, this is exactly the kind of thing they’re used for.

    Here is an example of two different Views using two different Models that both implement an interface. This is subtyping instead of ad-hoc polymorphism.

    public class ViewModelOne : IReusableView
    {
        public string Name { get; set; }
        public string Something { get; set; }
        public int ANumber { get; set; }
    }
    
    public class ViewModelTwo : IReusableView
    {
        public string Name { get; set; }
        public string Thing { get; set; }
        public string SomethingElse { get; set; }
        public int ANumber2 { get; set; }
    }
    
    public interface IReusableView
    {
        string Name { get; }
    }
    

    So we have the really simple partial view here that is ‘InnerPartialView’:

    @model TestIntegration.Models.IReusableView
    <div>
        @Model.Name
    </div>
    

    Which is used in the home and about pages of this example controller:

        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                ViewBag.Message = "Welcome to ASP.NET MVC!";
    
                return View(new ViewModelOne() { Name = "hello", Something="sdfsdfs", ANumber = 1 });
            }
    
            public ActionResult About()
            {
                return View(new ViewModelTwo() { Name = "hello 2", SomethingElse = "aaaddd", ANumber2 = 10, Thing="rand" });
            }
        }
    

    The home view:

    @model TestIntegration.Models.ViewModelOne
    @{
        ViewBag.Title = "Home Page";
    }
    
    <h2>@ViewBag.Message</h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
        @Html.Partial("InnerPartialView")
    </p>
    

    The about view:

    @model TestIntegration.Models.ViewModelTwo
    @{
        ViewBag.Title = "About Us";
    }
    
    <h2>About</h2>
    <p>
         Put content here.
             @Html.Partial("InnerPartialView")
    </p>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's consider the following scenario: a function which can generate code colors from white
Let's say I have a structure named vertex with a method that adds two
Let assume we have two activities. A - main activity, that is home launcher
let us assume that I have a reusable business layer that further makes use
Let's say I have an (x,y) that is always the same for the start
Let's say i have two tables in db: Car and Part. Car owns arbitrialy
Let me start by telling you that I never used anything besides SVN and
Let's assume that I am at manual A. I press enter and I am
Let me state up front that I have an infantile understanding of Monads. I
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and

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.