Im new for MVC, and when I built the model classes for the first code approach, each key identifier column had the [ScaffoldColumn(false)]
attribute. I did this because I do not need the identifiers displayed in the views, obviously, and I know that working on this problem will remove the HTML generated by the user interface in each view containing the identifier field.
The problem I encountered when using the ScaffoldColumn
set to false
in models was first noticed when the Edit method for the view was canceled, and I got this error: the Store application update, insert or delete fixed unexpected number of rows (0). When I ran the code in debugging, the ID property was actually set to zero, as indicated in my Edit HttpPost
method.
My question, to which I hope someone can think about whether it makes sense to have an attribute of type ScaffoldColumn
in MVC, if the identifier is not sent to the controller method, as in this case Edit HttpPost
? Should I just use this old fashion method and remove the HTML markup in every view created by MVC temples generated when this attribute is not added to the key / foreign key properties?
The work I discovered if you set this attribute to false
added an ID parameter to each HttpPost
method, rather than setting the corresponding ID property field before calling SaveChanges()
.
source share