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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:09:57+00:00 2026-06-18T05:09:57+00:00

It has been some time i try figuring out this! Generally: i want to

  • 0

It has been some time i try figuring out this!
Generally: i want to get a “Readonly, Hidden” Property from my Form.

I Trimmed all that is unncessey from the example:
i have the following Model

public class ChangeOrderDetailModel
{
...
...
    [ReadOnly(true)]
    public int OrderId { get; set; }
}

and in the View:

@using (Html.BeginForm("SubmitChangeOrder", "Order"))
{
    @Html.AntiForgeryToken()<br/>
    @Html.HiddenFor(o => o.OrderId) <br />
...
...
}

Now:

  1. in the View HTML, there is a hidden field for OrderID…

  2. I dont want anyone to change “OrderID” cause it can cause security issues.

  3. I need the OrderID number at the form submit…

  4. Problem When the form is submitted to the Controller
    OrderController.SubmitChangeOrder(ChangeOrderDetailModel mdl){}
    i see that mdl.OrderID is always = 0.

  5. When I remove the ReadOnly(true) attribute from the propertie, everything works ok, but anyone can change the value of the field using simple JS, which is VERY BAD.
    and i dont want to relay only on a hash token cause it is easly broken too 🙁

Why is it working like this?
Am i missing something, a better way to achive what i like?

note: there might be several change orders going on in parallel so session is kinda problematic.

Thanks to all.

  • 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-06-18T05:09:59+00:00Added an answer on June 18, 2026 at 5:09 am

    By using [Readonly(true)] you are explicitly instructing the model binder not to bind the field to the property of the model. By rendering the property using Html.HiddenFor have already achieved what you want in your rendered html. You can include a second parameter in your controller action as int OrderId and the model binder will bind the value on to that variable

    A rogue user may still be able to edit OrderId. One way to guard it against such action is to encrypt OrderId and use the encrypted value in the model and subsequently on the page. Then once the postback happens, you will decrypt the encrypted OrderId. Encryption and decryption could be encapsulated in to the model itself

    @TomerW, if I understood your question correctly, your core issue is that a rogue user can change the value of OrderId at the client side, My suggestion is not to render OrderId in its bare form, but encrypt it at the server side using a key only known at the server. You should render the encrypted value in HTML as a hidden filed. A rogue user may still attempt to change the associated value, but decryption will fail and you will know that someone has tried to fiddle with your value. Following is a stub implementation,

    public class ChangeOrderDetailModel
    {
        [ReadOnly(true)] /*You are instructing the model binder not to bind this value*/
        public int OrderId { get; set; }
    
        private string _OrderIdEnc;
        public string OrderIdEnc
        {
            /*Encryp*/
            get
            {
                return Encrypt(OrderId);
            }
    
            set
            {
                _OrderIdEnc = value;
            }
        }
    
        public void DecryptPayload()
        {
            /* Decrypt, and this will fail is someone has edited the value */
            OrderId = Decrypt(_OrderIdEnc);
        }
    }
    

    In your view model, use @Html.HiddenFor(o => o. OrderIdEnc). You can use standard windows crypto to do the encryption and decryption.

    To be extremely safe, you can use a different key for each req/response session. This will prevent a more advanced rogue user from replacing OrderIdEnc with an older version.

    I am sure that there may be other solutions, but above is a pattern that I have used many times and has worked

    Cheers

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

Sidebar

Related Questions

So this has been bugging me for some time and I can't seem to
Ok so this question has been bothering me for some time. I'm running a
This question has been bugging me for some time. I always picture launching my
This question has been bugging me for some time. I've already developed a couple
I apologize if this has been answered, I've searched for some time and could
This has been bugging me for some time now. My problem is the following.
This problem has been driving us nuts for some time. We have applications, all
PHP 5.3 has been released some time ago and the developers tried to keep
The classic approach to web development has been for some time a thin client
Visio has been supporting UML diagrams for quite some time now. Microsoft has now

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.