1 out of 2 rated this helpful - Rate this topic

InputExtensions.Hidden Method (HtmlHelper, String, Object)

Returns a hidden input element by using the specified HTML helper, the name of the form field, and the value.

Namespace:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
public static MvcHtmlString Hidden(
	this HtmlHelper htmlHelper,
	string name,
	Object value
)

Parameters

htmlHelper
Type: System.Web.Mvc.HtmlHelper
The HTML helper instance that this method extends.
name
Type: System.String
The name of the form field and the ViewDataDictionary key that is used to look up the value.
value
Type: System.Object
The value of the hidden input element. If this value is null, the value of the element is retrieved from the ViewDataDictionary object. If no value exists there, the value is retrieved from the ModelStateDictionary object.

Return Value

Type: System.Web.Mvc.MvcHtmlString
An input element whose type attribute is set to "hidden".

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

The difference between calling the Hidden method and using an input element is that the Hidden method is designed to make it easy to bind to view data or model data.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Correction / Clarification
The above documentation for the value parameter is incorrect. A more accurate documentation would be:

value
Type: System.Object
The value to use for the hidden input element when "name" is not present in either the ModelStateDictionary or ViewDataDictionary objects.

The following information would also have clarified matters further:

Return Value
Type: System.Web.Mvc.MvcHtmlString
An input element whose type attribute is set to "hidden". The value attribute will be set to:
  • The value of the "name" parameter in ModelStateDictionary, if present, otherwise
  • The value of the "name" parameter in ViewDataDictionary, if present, otherwise
  • The "value" parameter.

Remarks

In common with the other InputExtensions such as TextBox, the value attribute will be automatically repopulated from the ModelStateDictionary where a value is available, retaining the value last posted by the user. Where this is not what is required, an input element of type hidden should be used instead.