When creating a scaffolded item (CRUD) Visual Studio creates multiple pages, I have a question in regards to the editing page. Here it creates the default layout to update your model which can be modified to meet your needs. The problem I see is that it creates a hidden input field for your Id. Isn't this a security issue since the input control can be edited? If this is edited, when you save by theory it would update a different item (hence a security issue)? Also What if I have a second field that shouldn't be edited for example "CreatedBy" should I just be creating another hidden field? If this field is also edited i will lose my original CreatedBy user.
Also if I remove these hidden input boxes to remove the security threat the issue I face is that the automatic validation will fail because it won't retain my Id or CreatedBy user on the model. This is also an issue when updating because the Id would also be lost. Whats the best and the proper way to handle this?
Below is a sample of the automatic code created by visual studio when you create a scaffolded item (CRUD):
...
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="Test.Id" />
<div class="form-group">
<label asp-for="Test.Created" class="control-label"></label>
<input asp-for="Test.Created" class="form-control" />
<span asp-validation-for="Test.Created" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Test.CreatedBy" class="control-label"></label>
<input asp-for="Test.CreatedBy" class="form-control" />
<span asp-validation-for="Test.CreatedBy" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Test.Blahblah" class="control-label"></label>
<input asp-for="Test.Blahblah" class="form-control" />
<span asp-validation-for="Test.Blahblah" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
...
Anyhow I know this is something basic and I have been looking online for an answer to this but haven't been able to find one. I have found ways to check specific properties during validation, but this still will not ensure that I don't lose the Id and CreatedBy fields assuming I remove the hidden inputs.
It seems as if my only option is to have a security issue but I refuse to believe this is the correct method. Anyhow thank for the help!