views:

44

answers:

3

While a record is edited,how should be the ID stored ? I could have a textbox with enabled false, but I don't like this approach.

In ASP.NET I used to have a property which has saved the value in viewstate(Actually a hidden field + encrypted value).

The only solution I found Is to use a hidden field. Is it save enough ?

Are there any others options ?

+4  A: 

If you wish it to work in stateless mode, you need to add id to the url.

http://mywebsite/users/123/edit

Otherwise use the Session collection.

There is also the TempData collection to store data between two requests only. It may or may not be of use to you though.

P.S. Hidden field is also an option.

Developer Art
+1 The url is, in my opinion, the right place to have the id.
Mattias Jakobsson
+1  A: 

Hello user137348,

Is the ID auto-generated by SQL Server?

If yes, hiding this is an approach you can consider. Either you can hide it or remove it entirely.

We removed all the ID textboxes on our ASP.NET MVC Projects.

Cheers

Shaharyar
A: 

It is save enough if you check permissions.

If a user is allowed to edit something with ID 1 and 2 nothing happens if he decides do change the ID. If he changes ID 1 to ID 2 it is the same as if he edits the dataset with ID 2 in the userinterface. If he tries to change the ID to 3 you have to block it ("You are not allowed to edit this dataset ...")

chbu