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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:22:21+00:00 2026-06-18T07:22:21+00:00

Trying to move some code from an MVC3 project to an MVC4 project, and

  • 0

Trying to move some code from an MVC3 project to an MVC4 project, and running into this issue. There are some DisplayTemplates within an area, like so:

MVC Project
--Areas
----Identity
------Controllers
--------MyHomeController.cs
------Models
--------MyHomeViewModel.cs
--------MyEmailAddress.cs
------Views
--------Shared
----------DisplayTemplates
------------MyEmailAddress.cshtml
----------MyHome.cshtml
--------ViewStart.cshtml
--------Web.config
------IdentityAreaRegistration.cs

The MyHomeController has an action which returns the MyHome.cshtml view, strongly-typed to the MyHomeViewModel. MyHomeViewModel contains an IEnumerable<MyEmailAddress> property. Within the ‘MyHome.cshtml’ file, I have the following:

@foreach (var email in Model.Emails)
{
    @Html.DisplayFor(m => email)
}

However, this is not rendering the MyEmailAddress.cshtml Template. Same results with both of the following:

@foreach (var email in Model.Emails)
{
    @Html.DisplayFor(m => email, "MyEmailAddress")
}

@foreach (var email in Model.Emails)
{
    @Html.DisplayFor(m => email, "~/Areas/Identity/[rest of path]/MyEmailAddress.cshtml")
}

However, if I move the MyEmailAddress.cshtml file into the root web project’s Views/Shared/DisplayTemplates folder, it does render using this template.

For some reason, the DisplayFor HtmlHelper is either not looking in the area-specific Views/Shared/DisplayTemplates folder, or it is looking for something else in that folder.

What am I doing wrong? This works in MVC3, but I can’t seem to get it right in the MVC4 project.

  • 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-18T07:22:23+00:00Added an answer on June 18, 2026 at 7:22 am

    Once again I immediately found my own answer right after giving up and posting this question.

    The MyHomeController was using AttributeRouting. I discovered that if I went to the URL /Identity/MyHome/Action, the DisplayTemplate was being successfully chosen. However for my custom route, /my/home, it was not. Adding the following attribute to MyHomeController fixed this:

    [RouteArea("Identity")]
    public class MyHomeController : Controller
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to move some reusable portions of code into a class. This is
I'm trying to move some old code from hand-made persistence to Hibernate. The issue
I am trying to move some custom drawing code from a view into a
I need to move some code from C# into a Stored Procedure for speed
I'm trying to refactor some code and move some of my before_filter's from the
I'm trying to move some JavaScript code from MicrosoftAjax to JQuery. I use the
I am trying to move some model code to a module. The original model
Trying to move some divs using hover, this is my markup: <div class=item dark-grey>
I am trying to move from MySQL to MySQLi but am having some problems.
I'm trying to generate some LaTeX code which from thereon should generate PDF documents.

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.