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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:21:13+00:00 2026-05-27T21:21:13+00:00

I have this model: public class ExchangeRate { [Key] public int ExchangeRateID { get;

  • 0

I have this model:

public class ExchangeRate
{
    [Key]
    public  int ExchangeRateID { get; set; }
    [Required]
    [Display(Name = "Currency:")]
    public  string Currency { get; set; }
    [Required]
    public  decimal Rate { get; set; }
}

The “Create” view is working fine, but when I am in the edit view, I only want the Currency property to be displayed, and not editable. How should I do this? If I create another “view-only” model for this class, then I would omit the “Currency” property and would not be able to display it.

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
    <legend>ExchangeRate</legend>

    @Html.HiddenFor(model => model.ExchangeRateID)

    <div class="editor-label">
        @Html.LabelFor(model => model.Currency)
    </div>
    <div class="editor-field">
         @Html.DisplayFor(model => model.Currency)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Rate)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Rate)
        @Html.ValidationMessageFor(model => model.Rate)
    </div>

    <p>
        <input type="submit" value="Save" />
    </p>
</fieldset>

}

Changing @Html.EditorFor(model => model.Currency) to @Html.DisplayFor(model => model.Currency) doesn’t work because the model state becomes invalid when it posts back to the controller.

  • 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-27T21:21:14+00:00Added an answer on May 27, 2026 at 9:21 pm

    You could add

    @Html.HiddenFor(model => model.Currency)
    

    in your form and then use

    @Html.DisplayFor(model=> model.Currency)
    

    to display the readonly value of the currency property. That way when you post the value will be sent along in the posted model.

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

Sidebar

Related Questions

So I have this model setup public class ListOfThings { public int Id {get;set;}
I have this Model public class SalesModelView { [Key] public int SaleId { get;
I have this model: public class Package { public string CustomerName { get; set;
I have the following model: public class A { public int? Id {get;set;} public
I have this model : public class Person { public string Name { get;
In the world of MVC I have this view model... public class MyViewModel{ [Required]
Suppose I have this model: public class ViewModel { [Required] public string UserInput {
I have the following model: public class Hotfix { public int? released_version { get;
I have the following model: public class Person { public string Name { get;
My Model: public class EntryModel { [Required] public string Date { get; set; }

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.