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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:16:50+00:00 2026-05-23T13:16:50+00:00

I am using ASP.NET MVC 3 and have several pages where the majority of

  • 0

I am using ASP.NET MVC 3 and have several pages where the majority of the View Model is read-only. An example field would be like such:

<div class="display-label">My Field</div>
<div class="display-field">@Model.MyField</div>

I then have a field where the user has to type in some verification text like so:

@Html.LabelFor(model => model.Verification)
@Html.PasswordFor(model => model.Verification)

When the user submits the form and it hits my controller, the ViewModel’s fields are all null except for the Verification field. The way I have gotten around this, thus far, is to have several HiddenFor fields like such:

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

However, this gets ugly really fast. Is there a better way to handle the model in the view state so during the POST of the form submission, I can get all of my fields? This is important in case the verification text does not match during the POST and I need to return the view model without re-retrieving it from the database.

Thanks for any suggestions.

  • 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-23T13:16:50+00:00Added an answer on May 23, 2026 at 1:16 pm

    There is no better way around it without re-retrieving the value from the database. The reason is because MVC’s model binding only looks at the GET or POST parameters to bind the MyField to the action’s model, and if the GET/POST parameters don’t have a MyField value then it has to keep that property as null (how else is it going to know what the value shouldbe?)

    In order for the model binder to see your MyField value is to pass it in the GET/POST parameters, and to do this you have to explicitly tell your view’s form to pass the value in via Html.HiddenFor(). There’s no way for the view to automatically know to send that property in the post/get parameters.

    However one idea you can look at is to create a Razor (or Html) helper method that takes a field name and an expression (the x => x.MyField) and writes the following output for you:

    <div class="display-label">My Field</div>
    <div class="display-field">@Model.MyField</div>
    @Html.HiddenFor(model => model.MyField)
    

    This means you only have to write one line of code (something like @Html.ShowReadOnlyField(x => x.MyField, "My Field") instead of those 3 lines. However, this also assumes that everywhere you want to do this will have the same div structure.

    Edit: Just keep in mind the security concerns about read-only fields, because they aren’t truly read-only.. It is better to re-retrieve this data from the database if this data is going to be used for anything in the controller, because even though it’s read only on the HTML form, users can still set this value to anything they want by manipulating the POST/GET data.

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

Sidebar

Related Questions

I have several performance issue in my website. I'm using asp.net mvc 2 and
I'm using ASP.NET MVC and have a model which has an image (byte array)
I am using the telerik ASP.NET MVC Grid template and currently have several check
I'm using ASP.NET MVC 2 and have a login page that is secured via
Using ASP.Net MVC on my Site.Master I have: <head runat=server> <title><asp:ContentPlaceHolder ID=TitleContent runat=server />
Using ASP.NET MVC 2.0, I have an actionlink that is used for comments on
I'm using ASP.NET MVC RC2. I have a set of classes that were auto-generated
I wrote an application using ASP.NET MVC, in this application I have an Index
I am using ASP.NET MVC 1.0. I have an ActionResult which receives a form
we have a mixed development environment using ASP.NET MVC and Ruby on Rails. We

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.