隐藏编辑标记公物调用EditorFor(...)什么时候? [英] Hide editor-label for public property when calling EditorFor(...)?
本文介绍了隐藏编辑标记公物调用EditorFor(...)什么时候?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
致电时 Html.EditorFor(M = GT; M)
,其中 M
是一个公共类的公共性质,一个隐藏的输入和标签将显示的属性与 [HiddenInput]
属性。
- 如何隐藏标签没有使它私人或创建一个编辑模板?
示例
公共类用户
{
[HiddenInput]
公众的Guid ID {搞定;组; } //不应显示在编辑模板
公共字符串名称{;组; } //应该为可编辑
}
令人失望的结果为ID属性通过 EditorFor(...)
的与的标签
< DIV CLASS =编辑标记>
<标签=ID> ID< /标签> <! - 这是为什么在这里? - >
< / DIV>
< DIV CLASS =主编场>
<输入ID =IDNAME =ID类型=隐藏值=>
< / DIV>
解决方案
与解决:
[HiddenInput(DisplayValue = FALSE)]
否则 HideSurroundingHtml
设置不正确。
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>
解决方案
Solved with:
[HiddenInput(DisplayValue=false)]
Otherwise HideSurroundingHtml
is not set correctly.
这篇关于隐藏编辑标记公物调用EditorFor(...)什么时候?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文