I believe that the reason for not being included in System.ComponentModel.DataAnnotations is that this assembly is part of BCL and existed before ASP.NET MVC. Brad Wilson wrote a nice post that describes the metadata of the MVC model that you can read.
However, you can use the [UIHint] attribute:
public class MyViewModel { [UIHint("Hidden")] public string Value { get; set; } }
And in ~/Views/Home/EditorTemplates/Hidden.ascx :
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %> <%: Html.HiddenFor(x => x) %>
Now you can use <%= Html.EditorForModel() %> in your view and select a custom template.
Of course, using [HiddenInput] preferable since it forces you to write less code, but if you don't want to reference System.Web.Mvc in your project, you still have a workaround for UIHint .
source share