Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 08, 2010 06:06 AM by Mikesdotnetting
Apr 07, 2010 04:58 AM|LINK
When using the "add view" dialog in vwd is there a common practice for presenting any primary key fields as readonly to the user in the view?
By default it appears the user could change the key field value (as it is presented in a textbox) and overwrite data for that record for which the key was accidentally changed to.
Do we have to store the original record's key and then make the key presented as a label and then on the update subtitute the original key value back in for the record?
Or is there something simpler?
Apr 07, 2010 06:26 AM|LINK
Alter the generated code to display the ID as a label or span instead of a textbox. Or remove the ID altogether from the generated code. With MVC 2, you can decorate the ID property of your object with [ScaffoldColumn(false)] to prevent it even appearing
in a template.
You might also put it in a hidden field which means it's accessible on Postback, but not visible to the user.
Apr 07, 2010 10:56 PM|LINK
Thanks I will try that.
Just out of curiosity, If I choose to remove it completely from the generated code in the "Edit View", when the view is posted back where was the original key value stored at? Basically how does it associate which record to update then?
Apr 08, 2010 06:06 AM|LINK
It can't, unless you append it to the URL somewhere. It wasn't until after I suggested that that I noticed you were talking about Edit scenarios, so I added the hidden field idea.