Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 870
Petrus Theron Avatar asked May 08 '10 09:05

Petrus Theron


1 Answers

Solved with:

[HiddenInput(DisplayValue=false)]

Otherwise HideSurroundingHtml is not set correctly.

like image 193
Petrus Theron Avatar answered Sep 24 '22 06:09

Petrus Theron