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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:39:44+00:00 2026-05-31T14:39:44+00:00

I have a simple product list, the products fall into two distinct categories and

  • 0

I have a simple product list, the products fall into two distinct categories and are displayed differently on the page depending on their category id.

Is it at all possible to nest DisplayTemplates of the same Model type e.g.

//DisplayTemplates/Product.cshtml
@model MyNameSpace.Product


@if (Model.CategoryId == (int)ASixthSenseCore.CategoryId.GiftCards)
{
    @Html.DisplayForModel("GiftCards")
}
else
{
    @Html.DisplayForModel("Merchandise")
}



//DisplayTemplates/GiftCards.cshtml
@model MyNameSpace.Product

<div>I am a Gift Card</div>


//DisplayTemplates/Merchandise.cshtml
@model MyNameSpace.Product

<div>I am Merchandise</div>


//My View
@mode List<MyNameSpace.Product>

@Html.DisplayForModel()

I’ve tried doing this and it doesn’t break, but it doesn’t work either, the Product template runs as expected – I’ve added some debug text which correctly outputs for each corresponding item in the Product List. I suspect there is some kind of blocking clause in the Template Engine to avoid it from disappearing up it’s own backside with recursive calls to the same template being a possibility of this scenario, having said that I thought I would ask as this would be a handy way to deal with multiple DisplayTemplates for lists without having to iterate them with a foreach loop.

  • 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-31T14:39:46+00:00Added an answer on May 31, 2026 at 2:39 pm

    Your code should work, assuming your templates are not in DisplayeTemplates folder.

    I would create separate subclasses of Product and create templates for them. This will keep the code cleaner and you wouldn’t have to put if statements everywhere.

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

Sidebar

Related Questions

I have a simple ListView paged by a DataPager giving a list of products.
I have two tables. One contains a list of products with the primary key
I have a list of products coming from a repository. Simple enough. Now I
I have a website with a list of products and each product has the
I have the following code to grab a list of Products $collection = Mage::getModel('catalog/product')->getCollection();
I have a simple JQuery Product list. When a user click an item, it
I have a simple list of products where zebra striping is achieved using the
I have two very simple tables. Product and ProductCategory (ProductCategory is like a 'lookup'
I have a simple ASP.NET MVC application, like movie sample. In the list.aspx page
With our product we have a simple backup tool for the sql server database.

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.