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

  • Home
  • SEARCH
  • 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 6748439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:33:54+00:00 2026-05-26T12:33:54+00:00

I have the following view model to query my table: QuestionViewModel.cs public enum TypeQuestion

  • 0

I have the following view model to query my table:

QuestionViewModel.cs

public enum TypeQuestion {
   Long = 1,
   Short = 2,
   Small = 3,
}

public class QuestionViewModel
{

    public string Name { get; set; }

    public string LastName { get; set; }

    public string Address { get; set; }

    public string MaxAge { get; set; }

    public string Category { get; set; }

    public string Account { get; set; }

    public TypeQuestion CurrentTypeQuestion { get; set; }
}

if the query I’m doing is of type:

Long: displays all fields.
Short: displays Name, LastName, Address, MaxAge.
Small: displays Name, LastName.

Is there any way to put some kind of DataAnnotation to determine which fields to display in the view or some other way?, To avoid putting a “what if?” for each field.

Thank you.

  • 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-26T12:33:55+00:00Added an answer on May 26, 2026 at 12:33 pm

    Based from this link and this link

    Controller:

    public ActionResult Consulta()
    {
        return View(new QuestionViewModel());
    }
    

    ViewModel:

    public enum TypeQuestion {
       Long = 1,
       Short = 2,
       Small = 3,
    }
    
    public class QuestionViewModel
    {
        public string Name { get; set; }
        public string LastName { get; set; }
        public string Address { get; set; }
        public int MaxAge { get; set; }
        public string Category { get; set; }
        public string Account { get; set; }
        public TypeQuestion CurrentTypeQuestion { get; set; }
    
        public bool EnabledField(ModelMetadata field)
        {
            //check pending implementation
            return true;
        }
    }
    

    View:

    @model MySite.QuestionViewModel
    @using System.Linq;
    @using System.Collections;
    
    @{
        ViewBag.Title = "Question";
        Layout = "~/Views/Shared/Layout.cshtml";
    }
    <h2>Question</h2>
    
    @using (Html.BeginForm(new { id = "FormQuestion" }))
    {
    
        foreach (var prop in ViewData.ModelMetadata.Properties
            .Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm) && ViewData.Model.EnabledField(pm)))
        {
            if (prop.HideSurroundingHtml)
            {
                Html.Editor(prop.PropertyName);
            }
            else
            {
                <div class="editor-label">
                    @(prop.IsRequired ? "*" : "")
                    @Html.Label(prop.PropertyName)
                </div>
                <div class="editor-field">
                    @Html.Editor(prop.PropertyName, prop.Model)
                    @Html.ValidationMessage(prop.PropertyName, "*")
                </div>
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view within an app called 'manager': class AddObj(CreateView): model =
I have a view model (below). public class TopicsViewModel { public Topic Topic {
in a partial view I have the following: <%Html.RenderAction(MVC.User.GetComments(Model.UserGroupName)); %> can I render a
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which
I have a model similar to the following: class Review(models.Model): venue = models.ForeignKey(Venue, db_index=True)
I have the following models: http://slexy.org/view/s20T8yOiKZ from mxutils.cms_services import generate_secid from django.db import models
I have following view <asp:Content ID=Content2 ContentPlaceHolderID=MainContent runat=server> <h2>Tables <%=ViewData[RetriverName] %></h2> <%using (Html.BeginForm(ResfreshSelectedTables, Home))
In a branch spec, I have the following view: //depot/dev/t/a/g/... //depot/dev/t/r/g/... -//depot/dev/t/a/g/p/o*/... //depot/dev/t/r/g/p/... Perforce
I have the following in my view: <%using (Html.BeginForm()) {%> <% foreach (var item

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.