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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:53:01+00:00 2026-05-21T19:53:01+00:00

I have a lot of problem for converting .ascx templates into razor syntax. Can

  • 0

I have a lot of problem for converting .ascx templates into razor syntax. Can anyone help me?

@{
bool ShouldShow(ModelMetadata metadata) {
    return metadata.ShowForDisplay
        && metadata.ModelType != typeof(System.Data.EntityState)
        && !metadata.IsComplexType
        && !ViewData.TemplateInfo.Visited(metadata);
    }
}

@if (Model == null) { 
    ViewData.ModelMetadata.NullDisplayText
} else if (ViewData.TemplateInfo.TemplateDepth > 1) {
    ViewData.ModelMetadata.SimpleDisplayText
} else {
    foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => ShouldShow(pm))) {
    if (prop.HideSurroundingHtml) {
        Html.Display(prop.PropertyName)
    } else {
        if (!String.IsNullOrEmpty(prop.GetDisplayName())) {
            <div class="display-label">@prop.GetDisplayName()</div>
        } 
        <div class="display-field">@Html.Display(prop.PropertyName)</div>
    } 
}

It’s seems above code is correct (at least from my perspective).

UPDATE

I don’t have any intellisense for ShouldShow method! why? I’ve a lot of compilation errors.

Error 1 } expected PATH\Object.cshtml 1 1 PROJ
Error 5 A namespace cannot directly contain members such as fields or methods PATH\Object.cshtml 11 3 PROJ
Error 4 Invalid token ‘}’ in class, struct, or interface member declaration PATH\Object.cshtml 11 1 PROJ
and so on!

  • 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-21T19:53:02+00:00Added an answer on May 21, 2026 at 7:53 pm

    To insert class-level members (such as your bool ShouldShow), you need to use an @functions block.

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

Sidebar

Related Questions

I have run into a strange problem, i am creating a lot of dynamically
Friends, I'm converting an Oracle Form to Apex and have run into problem(s?) which
I have trouble finding a solution for the following problem: I have a lot
This must be a common problem with a common solution. I have a lot
I've been dealing with a frustrating problem recently. I have a lot of reflection
I have read a lot of related topics here regarding this problem but I
I have a bizarre problem. I use a lot of session variables so I
I have a peculiar problem, which I think that a lot of other people
I have looked at past questions on this but I can't solve my problem
Lately we been having a lot of problems with our mysql server i have

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.