New to Telerik UI for ASP.NET MVC? Download free 30-day trial

Hidden Fields

The Telerik ASP.NET ASP.NET MVC Form component provides built-in support for hidden fields. You can use this feature to perform a number of actions such as hiding the ID property.

The following example demonstrates how to configure a Form with two visible and one hidden field (UserID).

       @(Html.Kendo().Form<Kendo.Mvc.Examples.Models.Form.UserViewModel>()
        .Name("formExample")
        .HtmlAttributes(new { action = "Index", method = "POST" })
        .Validatable(v =>
        {
            v.ValidateOnBlur(true);
            v.ValidationSummary(vs => vs.Enable(false));
        })
        .Items(items =>
        {
        items.AddGroup()
            .Label("Sign up form")
            .Items(i =>
            {
            i.Add()
                .Field(f => f.UserID)
                .Editor(editor => editor.Hidden());
            i.Add()
                .Field(f => f.UserName)
                .Label(l => l.Text("Username:"));
            i.Add()
                .Field(f => f.Password)
                .Label(l => l.Text("Password:"))
                .EditorTemplateHandler("setPasswordEditor");
            i.Add()
                .Field(f => f.Email)
                .Label(l => l.Text("Email:"));
            });
        })
    )

To add support for the HiddenInput attribute, use the following implementation:

        [HiddenInput]
        public int UserID
        {
            get;
            set;
        }
    @(Html.Kendo().Form<Kendo.Mvc.Examples.Models.Form.UserViewModel>()
        .Name("formExample")
        .HtmlAttributes(new { action = "Index", method = "POST" })
        .Items(items =>
        {
            items.Add()
                .Field(model => model.UserID);
        })
    )

To add a method for enabling the injection of the AntiForgeryToken input in:

   @(Html.Kendo().Form<Kendo.Mvc.Examples.Models.Form.UserViewModel>()
       .Name("formExample")
       .HtmlAttributes(new { action = "Index", method = "POST" })
       .Items(items =>
       {
           items.AddAntiForgeryToken();
       })
   )

See Also

In this article