Why doesnt <ScaffoldColumn(False)> work?
Its my understanding that by adding the ScaffoldColumn(false) annotation to an property in a class, that property will not added to the view when doing Add View. However even though i have added scaffoldcolumn false to properties i dont want added to a Create form, they are still rendered inthe create view. Is ScaffoldColumn broken? On page 552 in Pro ASP.NET MVC 3 Framework by Freeman and Sanderson, it states
"If we want to exclude a property from the generated HTML, we can use ScaffoldColumn attribute. When the scaffolding helpers see the ScaffoldColumn attribute, they skip over the property entirely; no hidden input elements will be generated and no details of this property will be included in the generated HTML."
Also the MVC Music Store PDF on p 77 indicates that the att开发者_如何学Pythonrtibute will do the same -
"Allows hiding fields from editor forms".
They add it to the AlbumId property and then when the app is run AlbumId field is not shown in the browser.
Is this attr broken?
If i change a html helper to DisplayFor it does not appear in the form regardless of whether scaffoldcolumn is present. For example i dont have scaffoldcolumn false on Property PostTitle but if i change @Html.EditorFor(Function(model) model.PostTitle)
to displayfor
then it does not render regardless of the scaffoldcolumn attr.
Also my Create view is strongly typed to @ModelType RiderDesignMvcBlog.Core.Entities.Post
Received this answer in the asp.net forums:
That statement is incorrect. The attribute is recognized by Dynamic Data, but not by MVC 3 Scaffolding. When I asked about this in March of this year, I got this response from the team that created the MvcScafolding Nuget package:
Yes, that particular bit of metadata just isn’t recognized by the MvcScaffolding T4 templates. There’s a lot of possible metadata, and a lot of code necessary to recognize and respond to it all, and we have to trade that off against keeping the T4 templates simple enough that people can understand and customize them and not be overwhelmed with all the logic. I don’t think the MVC 3 built-in Add View templates respond to that one either.
精彩评论