数据注释中的 Asp.Net Mvc 隐藏字段

发布于 2024-10-09 12:48:33 字数 133 浏览 0 评论 0原文

我以为这会是在谷歌上的快速搜索,但也许我错过了一些东西。有没有办法使用数据注释来设置 ViewModel 属性以在呈现标记时创建 HiddenInput?

我发现的唯一注释是从视图中完全隐藏该属性,我仍然希望呈现该属性,但作为隐藏输入。

I thought this would be a quick search on google but maybe I'm missing something. Is there a way, using Data Annotations, to set a ViewModel property to create a HiddenInput when the markup get rendered?

The only annotations I've found were to hide the property from the view entirely, I still want the property rendered but as a hidden input.

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

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

发布评论

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

评论(1

审判长 2024-10-16 12:48:33

该属性:

[System.Web.Mvc.HiddenInput(DisplayValue = false)]
public int Id { get; set; }

将渲染为 ie

<input id="Id" name="Id" type="hidden" value="21" />

使用 Html.EditorForModel()Html.EditorFor(m => m.Id)

This property:

[System.Web.Mvc.HiddenInput(DisplayValue = false)]
public int Id { get; set; }

will be rendered as i.e.

<input id="Id" name="Id" type="hidden" value="21" />

when using Html.EditorForModel() or Html.EditorFor(m => m.Id)

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