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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:13:22+00:00 2026-05-20T16:13:22+00:00

Several sub-classes (e.g. Cheese ) share common properties derived from a base class (

  • 0

Several sub-classes (e.g. Cheese) share common properties derived from a base class (Product) with properties like SKU, Name and Description.

To avoid duplication when rendering display/editor templates, I want each sub-class template (Cheese.cshtml) to render its unique fields below that of its shared common base class template (Product.cshtml).

However, casting from the derived class to the base class (Product)cheese and trying to display its template inside the sub-class template has no effect.

DisplayTemplate File structure:

.\Views\Shared\DisplayTemplates
    .\Product.cshtml -- renders common base class fields
    .\Cheese.cshtml -- renders unique class fields and calls Product.cshtml

Cheese.chtml:

@model Application.Data.Models.Cheese

@{
    var product = (Application.Data.Models.Part)Model;
}

Base Product Fields:
@Html.DisplayFor(x => products, "Product") @* no effect! *@

<div class="field">
    <div class="display-label">@Html.LabelFor(m => Model.UniqueProperty)</div>
    <div class="display-field">@Html.DisplayFor(m => Model.UniqueProperty)</div>
</div>

Casting to the base class and rendering the Product.cshtml template works fine from a View, but not from within the sub-class template.

How can I render a common template for my base class from within my sub-class templates?

  • 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-20T16:13:23+00:00Added an answer on May 20, 2026 at 4:13 pm

    Solution Found

    @Html.DisplayFor(...) cannot be nested, so you have to use @Html.Partial in your derived template like so:

    @Html.Partial("~/Views/Shared/DisplayTemplates/Product.cshtml", product) %>
    

    Or, if your file structure allows it, a more terse path:

    @Html.Partial("DisplayTemplates/Product", product)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a super class 'Node' and several sub classes e.g. 'SubNode1', 'SubNode2' etc.
I have a base class and several subclasses. Each sub class has an attribute
I have a class, Document and several sub-classes ( Invoice , PurchaseOrder , etc).
I have an abstract base class called Party. There are several concrete subclasses (Company,
I am attempting to share a sub menu among several different parts of an
I have a main class with a category property and several subclasses. I'd like
Is there a base class that I should inherit from that is just a
I have a Role and several classes that mix-in the role. The Role class
Say I have one superclass, and several subclasses inheriting it. I'd like to cram
I have a project divided into several sub-modules (each of them are jar libraries):

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.