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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:55:22+00:00 2026-05-25T09:55:22+00:00

I have to make a large amount of forms for a project I’m working

  • 0

I have to make a large amount of forms for a project I’m working on. Every form has a large amount of fields in them. Would it be possible to create an HTML helper that can display an element or edit element depending on some variable? Maybe someone has tried this already. I could imagine that It would be something like:

@Html.EditOrDisplayFor(m=>m.Field, isReadonly)

When it is readonly it displays only the variable and when it is not it shows an textbox. Beside this helper I need some if’s in my views, but it saves a couple of 100 lines of code if this would be possible)

  • 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-25T09:55:23+00:00Added an answer on May 25, 2026 at 9:55 am

    Just found an alternative (I think quite neat way) to do it:

        public static MvcHtmlString EditOrDisplayFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> p,bool readOnly){
            if (readOnly){
                return new MvcHtmlString(string.Format("{0}", html.DisplayFor(p)));
            }  else{
                return new MvcHtmlString(string.Format("{0}", html.EditorFor(p)));
            }
    
        } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement to make a large amount of code MISRA compliant. First
I have a large amount of Data, which has to be arranged in the
I have a stored procedure that is working with a large amount of data.
I have created a large amount of Task instances. I need to run them
I have a control which I have to make large modifications to. I'd like
I have been developing an asp.net mvc application where i need to make large
I have a large system that I have coded and I wish to make
I have a java applet in which I have to display a large amount
I have a JTextArea in Java. When I place a large amount of text
I have a large amount of text data that I want to display in

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.