0

I have a User table where I keep the profile information of the user along with some system generated columns and password.

I am using a model to query the database and send the result to the user. User modifies the profile information and send the request which I am using the same Model to deserialize. But I don't want the user to change those system generated fields.

What should I do?

svick
  • 236,525
  • 50
  • 385
  • 514
Prashant
  • 3,823
  • 3
  • 25
  • 40
  • I don't understand your question? If you don't want a user to modify some fields why are you exposing them to the user? – Dawid Rutkowski Nov 16 '16 at 07:22
  • @DawidRutkowski They should be able to view the values - Read-Only fields. – Prashant Nov 16 '16 at 07:49
  • Then simply disable the edition of those fields on the client side. You might also reset changes in those fields (or simply don't update them) on the server side when user will submit his changes. – Dawid Rutkowski Nov 16 '16 at 08:04
  • @DawidRutkowskiThanks. This is precisely what i am doing right now but I thought there may be a better way to do by putting some annotations on model fields. – Prashant Nov 16 '16 at 08:08

1 Answers1

2

Regarding the Data Annotation attributes - try marking Property with ReadOnly attribute.

[ReadOnly(true)]
public decimal BodyMassIndex { get; private set; }

Look here for more details.

Community
  • 1
  • 1
Dawid Rutkowski
  • 2,658
  • 1
  • 29
  • 36