I have a model which has several fields which I never want to be editable by the user. How can I create an edit page which not only hides these fields, but also protects against the user injecting the input elements themselves?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Take a look at
TryUpdateModel()(MSDN article found here.). You can specify a black-list and white-list of what you’d like the method to actually update:Along with that, I’d make sure that your posted model doesn’t contain the fields that you want the user to update, though that can be overriden with a hand-crafted form post. This will at least help you ensure you’re not accidentally putting fields on the page you don’t want edited.