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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:30:23+00:00 2026-05-21T04:30:23+00:00

If i have a ViewModel like this: public class SignupViewModel { [Required] [DisplayName(Email:)] public

  • 0

If i have a ViewModel like this:

public class SignupViewModel
{
   [Required]
   [DisplayName("Email:")]
   public string EmailAddress { get; set; }   
}

And use EditorFor to render out the form fields:

@Html.EditorFor(model => model.EmailAddress )

It will render <input type="text">. Cool.

But in this particular scenario, i have already retrieved Email from a different source, and i wish to pre-fill the form with this data, and show a label instead of a textbox (as i don’t want them to change their email – don’t worry about why).

I know i can use [UIHint], but can i do that programatically from the controller?

E.g:

var model = new SignupViewModel();
model.EmailAddress = GetFromMysterySource(); // How do i set a UIHint?

What’s the best way to approach this? Should i use a seperate ViewModel altogether, which could mean changing my View from being strongly-typed to being dynamic, or should i not use EditorFor, or should i use a custom editor template?

Suggestions/advise would be greatly appreciated.

  • 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-21T04:30:23+00:00Added an answer on May 21, 2026 at 4:30 am

    You can’t apply an attribute at runtime. My suggestion would be to build a bit of logic into your view to control how the view renders the data. You may need to augment your model to indicate to the view which display to choose.

      @if (Model.EmailAddressIsFixed)
      {
         @Html.DisplayFor( m => m.EmailAddress )
         @Html.HiddenFor( m => m.EmailAddress ) // only if you need it to post back
      }
      else
      {
         @Html.EditorFor( m => m.EmailAddress )
      }
    

    If you are doing this in more than one place, then a custom editor template doing the same thing would probably be in order.

      @Html.EditorFor( m => m.EmailAddress, 
                       "FixedAddressTemplate",
                       new { Fixed = Model.EmailAddressIsFixed } )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have ViewModel class MyViewModel like: public class MyViewModel : ViewModelBase { private
I have a Create view which is passed a ViewModel. The ViewModel contains the
I did a search on SO and looks like this question gets asked quite
When using Josh Smith's RelayCommand , most of the examples I've seen use lazy
I'm attempting to use the script found from http://valums.com/ajax-upload/ My controller is as follows
i have an asp.net mvc page and i want to have a dropdown list
My problem is hydrating a Viewmodel from a Linq2Sql object that has been returned
I've been trying to figure this for a few days now, with no luck.
I'm using a Silverlight 4.0 project that utilizes MVVM and we have a combobox
Hello fellow StackOverflow users (or Stackoverflowers ?): I'm learning-by-coding WPF. I read several articles/saw

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.