Hide editor-label for public property when calling EditorFor(…)?

你离开我真会死。 提交于 2019-12-30 09:06:14

问题


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>

回答1:


Solved with:

[HiddenInput(DisplayValue=false)]

Otherwise HideSurroundingHtml is not set correctly.



来源:https://stackoverflow.com/questions/2793545/hide-editor-label-for-public-property-when-calling-editorfor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!