Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 3: Hide ID property using EditorForModel

I have this line in my View:

@Html.EditorForModel()

And this is my ViewModel:

public class CommentForm
{
    public int Id { get; set; }

    [DisplayName("Kommentar"), DataType(DataType.MultilineText)]
    public string Comment { get; set; }
}

The problem is that Id renders as a textfield in the form. Actually, I only want to use Id in the form action. Is there an attribute that tells the editor not to render the property Id?

like image 785
Bridget the Midget Avatar asked Nov 26 '22 21:11

Bridget the Midget


1 Answers

Setting ShowForDisplay and ShowForEdit to false is already done by the standard

 [System.ComponentModel.DataAnnotations.ScaffoldColumn(false)] 

attribute. Your custom attribute therefore seems like overkill.

like image 79
Georg Patscheider Avatar answered Jan 10 '23 15:01

Georg Patscheider