调用 EditorFor(...) 时隐藏公共属性的编辑器标签?
调用 Html.EditorFor(m => m)
时,其中 m
是具有公共属性、隐藏输入和标签的公共类对于具有 [HiddenInput]
属性的属性,将显示这些信息。
- 如何隐藏标签而不将其设为私有或创建编辑器模板?
示例
public class User
{
[HiddenInput]
public Guid ID { get; set; } // should not be displayed in editor template
public string Name { get; set; } // should be editable
}
EditorFor(...)
with 标签的 ID 属性结果不理想
<div class="editor-label">
<label for="ID">ID</label> <!-- Why is this here? -->
</div>
<div class="editor-field">
<input id="ID" name="ID" type="hidden" value="">
</div>
When calling Html.EditorFor(m => m)
, where m
is a public class with public properties, a hidden input and a label are displayed for properties with the [HiddenInput]
attribute.
- How can I hide the label without making it private or creating an editor template?
Example
public class User
{
[HiddenInput]
public Guid ID { get; set; } // should not be displayed in editor template
public string Name { get; set; } // should be editable
}
Undesired result for ID property by EditorFor(...)
with label
<div class="editor-label">
<label for="ID">ID</label> <!-- Why is this here? -->
</div>
<div class="editor-field">
<input id="ID" name="ID" type="hidden" value="">
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法:
否则
HideSurroundingHtml
设置不正确。Solved with:
Otherwise
HideSurroundingHtml
is not set correctly.