为什么不工作?

发布于 2024-12-07 15:28:27 字数 933 浏览 3 评论 0原文

据我了解,通过向类中的属性添加 ScaffoldColumn(false) 注释,在添加视图时该属性不会添加到视图中。然而,即使我已将 scaffoldcolumn false 添加到我不想添加到创建表单的属性,它们仍然呈现在创建视图中。 ScaffoldColumn 是否损坏?在 Freeman 和 Sanderson 的 Pro ASP.NET MVC 3 Framework 第 552 页上,它指出

“如果我们想从生成的 HTML 中排除某个属性,我们可以使用 ScaffoldColumn 属性。当脚手架工看到 ScaffoldColumn 属性,它们完全跳过该属性;不 将生成隐藏的输入元素,并且没有详细信息 属性将包含在生成的 HTML 中。”

第 77 页上的 MVC Music Store PDF 也表明该属性将执行相同的操作 -

“允许隐藏编辑器表单中的字段”。

他们将其添加到 AlbumId 属性,然后当应用程序运行时,AlbumId 字段不会显示在浏览器中。

这个attr坏了吗?

如果我将 html 帮助程序更改为 DisplayFor,无论脚手架列是否存在,它都不会出现在表单中。例如,我在Property PostTitle上没有scaffoldcolumn false,但是如果我将@Html.EditorFor(Function(model) model.PostTitle)更改为displayfor,那么无论什么情况它都不会渲染脚手架列属性。

另外,我的 Create 视图被强类型化为 @ModelType RiderDesignMvcBlog.Core.Entities.Post

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 attrtibute 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云柯 2024-12-14 15:28:27

在 asp.net 论坛中收到这个答案:

这个说法是不正确的。该属性被 Dynamic 识别
数据,但不是通过 MVC 3 脚手架。当我三月份问起这个问题时
今年,我从创建该项目的团队那里得到了这样的回应
MvcScafolding Nuget 包:

是的,元数据的特定部分无法被识别
Mvc脚手架 T4 模板。有很多可能的元数据,并且
识别和响应这一切所需的大量代码,我们有
权衡保持 T4 模板足够简单
人们可以理解并定制它们,而不会被淹没
所有的逻辑。我不认为 MVC 3 内置添加视图模板
对此做出回应。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文