Class FormFieldAttribute
Specifies that a parameter of a controller method will receive the value(s) of a field in a HTML form,
obtained by deserializing a request body with a content type of application/x-www-form-urlencoded
.
The parameter carrying this attribute can be either a simple type or a one-dimension array.
If multiple values are present for the field, a non-array parameter will receive the last specified value, while an array parameter will receive an array of field values converted to the element type of the parameter.
If a single value is present for the field, a non-array parameter will receive the value converted to the type of the parameter, while an array parameter will receive an array of length 1, containing the value converted to the element type of the parameter
If no values are present for the field and the BadRequestIfMissing property is
true, a 400 Bad Request
response will be sent to the client, with a message
specifying the name of the missing field.
If no values are present for the field and the BadRequestIfMissing property is false, a non-array parameter will receive the default value for its type, while an array parameter will receive an array of length 0.
This class cannot be inherited.
Implements
Namespace: EmbedIO.WebApi
Syntax
public sealed class FormFieldAttribute : Attribute, IRequestDataAttribute<WebApiController, string>, INonNullRequestDataAttribute<WebApiController, string[]>, IRequestDataAttribute<WebApiController>
Constructors
FormFieldAttribute()
Initializes a new instance of the FormFieldAttribute class. The name of the form field to extract will be equal to the name of the parameter carrying this attribute.
Declaration
public FormFieldAttribute()
FormFieldAttribute(Boolean)
Initializes a new instance of the FormFieldAttribute class. The name of the form field to extract will be equal to the name of the parameter carrying this attribute.
Declaration
public FormFieldAttribute(bool badRequestIfMissing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | badRequestIfMissing | If set to true, a |
FormFieldAttribute(String)
Initializes a new instance of the FormFieldAttribute class.
Declaration
public FormFieldAttribute(string fieldName)
Parameters
Type | Name | Description |
---|---|---|
String | fieldName | The name of the form field to extract. |
FormFieldAttribute(String, Boolean)
Initializes a new instance of the FormFieldAttribute class.
Declaration
public FormFieldAttribute(string fieldName, bool badRequestIfMissing)
Parameters
Type | Name | Description |
---|---|---|
String | fieldName | The name of the form field to extract. |
Boolean | badRequestIfMissing | If set to true, a |
Properties
BadRequestIfMissing
Gets or sets a value indicating whether to send a 400 Bad Request
response
to the client if the submitted form contains no values for the field.
If this property is true and the submitted form
contains no values for the field, the 400 Bad Request
response sent
to the client will contain a reference to the missing field.
If this property is false and the submitted form contains no values for the field, the default value for the parameter (or a zero-length array if the parameter is of an array type) will be passed to the controller method.
Declaration
public bool BadRequestIfMissing { get; }
Property Value
Type | Description |
---|---|
Boolean |
FieldName
Gets the name of the form field that this attribute will extract, or null if the name of the parameter carrying this attribute is to be used as field name.
Declaration
public string FieldName { get; }
Property Value
Type | Description |
---|---|
String |
Explicit Interface Implementations
INonNullRequestDataAttribute<WebApiController, String[]>.GetRequestDataAsync(WebApiController, String)
Declaration
Task<string[]> INonNullRequestDataAttribute<WebApiController, string[]>.GetRequestDataAsync(WebApiController controller, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<String[]> |
IRequestDataAttribute<WebApiController, String>.GetRequestDataAsync(WebApiController, String)
Declaration
Task<string> IRequestDataAttribute<WebApiController, string>.GetRequestDataAsync(WebApiController controller, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<String> |
IRequestDataAttribute<WebApiController>.GetRequestDataAsync(WebApiController, Type, String)
Declaration
Task<object> IRequestDataAttribute<WebApiController>.GetRequestDataAsync(WebApiController controller, Type type, string parameterName)
Parameters
Type | Name | Description |
---|---|---|
WebApiController | controller | |
Type | type | |
String | parameterName |
Returns
Type | Description |
---|---|
Task<Object> |