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

The Archive Base Latest Questions

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

First I have a Display Template in Views > Blog > DisplayTemplates: @model Domain.Model.BlogPost

  • 0

First I have a Display Template in Views > Blog > DisplayTemplates:

@model Domain.Model.BlogPost
<div class="blogSummary">
    @Html.ActionLink(Model.Title, "post", new { Id = Model.PostID }, new { @class = "titleLink" })
    <div class="subInfo">
        Posted by @Model.Author on @Model.PostedDate.ToString("D") | @Model.PostComments.Count
        Comment(s)</div>
    <br />
    <div class="summaryText">
        @Html.Markdown(Model.Body.Length > 300 ? Model.Body.Remove(0, 300) + "..." : Model.Body)
        @Html.ActionLink("(view more)", "post", new { Id = Model.PostID })
    </div>
</div>

Then I have a view:

@model IEnumerable<Domain.Model.BlogPost>
@{
    ViewBag.Title = "Index";
}
@Html.DisplayFor(x => x, "BlogPostSummary")

However, I am getting an error on the DisplayFor():

The model item passed into the
dictionary is of type
‘System.Data.Objects.ObjectSet`1[Domain.Model.BlogPost]’,
but this dictionary requires a model
item of type ‘Domain.Model.BlogPost’.

I’m having a bit of trouble understanding what’s going on. What is the best way to use the display template?

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

    The problem is you’re trying to pass in a collection of BlogPosts, when a single BlogPost is expected.

    Try:

    @Html.DisplayFor(x => x[0], "BlogPostSummary")
    

    Or something like:

    @foreach (var post in Model)
        @Html.Display(post)
    

    Note: I’m not convinced the second example is using Html.Display correctly. My suspicion is that the code would be better served using a partial instead of a display template.

    UIHint

    By default, ASP.NET MVC relies on naming conventions to link BlogPost the class to BlogPost.cshtml the display template. If however, you would like to use CustomBlogPost.cshtml as your display template, you can do so by applying the UIHint attribute.

    public class DomainModel {
        [UIHint("CustomBlogPost")]
        public BlogPost Post { get; set; }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to display images from the Photo Library using UIScrollview. Except the first
I want to display a UITableView with Multiple Columns. The first column will have
I have a table for which I want to display only the first row
In a frame I have two columns. In the first column I display some
First I have a PHP file that gets data and file from a HTML
I have a View Model that is defined as follows: public class VariableViewModel {
I have four <div> in one page. I want to display 25 records on
I have the following model in MVC: public class IndexViewModel { public SubViewModel SubViewModel
I`m trying to display classes that have properties of type some custom class inside
I may have overcomplicated things. I have two views. The first view generates a

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.