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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:23:55+00:00 2026-05-23T13:23:55+00:00

So as I understand it Given a view model public class MyViewModel{ public DateTime

  • 0

So as I understand it

Given a view model

public class MyViewModel{
    public DateTime Date {get; set;}
    public MyClass Class {get; set;}
}

.. a View Views\MyController\MyAction.cshtml

@model MyViewModel
@Html.DisplayForModel()

.. a partial View Views\Shared\DisplayTemplates\DateTime.chstml

@model DateTime
Some Date

.. another partial View Views\Shared\DisplayTemplates\MyClass.cshtml

@model MyClass
My Class

.. I should get

Date
Some Date
Class
My Class    

.. But I just get

Date
Some Date

So it seems DisplayForModel finds DateTime template but not my custom template, even though I am following the conventions of naming it by the type of the property.

Am I missing something. I am using MVC 3 and believe this feature was already available in MVC 2

  • 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-23T13:23:55+00:00Added an answer on May 23, 2026 at 1:23 pm

    Having perused the MVC source code, it turns out that this is, in fact, not possible.

    The reason is that @Html.DisplayForModel() attempts to find a template to use for rendering, by:

    • first looking for the name of the model’s type, i.e. MyViewModel.cshtml or MyViewModel.vbhtml or MyViewModel.ascx etc, in location ~\Views, ~\Views[ControllerName], ~\Views\DisplayTemplates, ~\Views\Shared, ~\Views\Shared\DisplayTemplates
    • if it is not found it will walk down the model’s base types, attempting each type’s name in turn
    • if none are found, it will eventually end up at Object, for which there exists a built-in template

    The object template is designed such that it retrieves all the model’s properties, for rendering, from metadata based on the following condition:

    metadata.ShowForDisplay
    && metadata.ModelType != typeof(EntityState)
    && !metadata.IsComplexType 
    && !templateInfo.Visited(metadata)
    

    Therefore any property that is a complex type will always be excluded. I think the confusion arises from Brad Wilson’s post on custom object template, where he creates a custom object template and addresses the issue of Shallow Dive vs Deep Dive. By implementing a custom deep dive object template this will override the built-in object template and complex types can be rendered.

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

Sidebar

Related Questions

Item is a simple model class. ItemComponent is a view for an Item which
as i understand sitecollection security ,member of a given sitecollection can not view another
A have a view created with Drupal's Views module, and have given it a
Can anybody point to/give a very very correct example for the Model-View-Controller paradigm? I
**models.py** class Category(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Gender(models.Model): name =
I'd like to understand how subversion stores revisions in FSFS, and how a view/shapshot
I understand how I can change the dns settings for my domains by editing
I understand what System.WeakReference does, but what I can't seem to grasp is a
I understand how JS is run and I think I understand most of the
I understand that some countries have laws regarding website accessibility. In general, what are

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.