一、Controls
通过前面的教程我们已经知道,vici mvc可以呈现一个绑定在某一个类中某个字段的控件,你只需要通过在某个字段上添加属性,告诉框架呈现哪个控件,这么呈现等。
你也可以明确的创建一个控件用来在视图里呈现,例如:
在视图中应该这么写:
二、Built-in controls
一般情况下所以的控件都有下列属性:
Property | Type | Description | |
---|---|---|---|
Id | String | The XHTML id to render the control with. This should be unique across the rendered page. If not set, the framework will generate a unique id for you. | |
Name | String | The name of the control, which is required and should only be set by the constructor | |
Error | Boolean | If set to true, the control will be renderd with the CSS class defined by the CssClassError property. If false, the CSS class defined by CssClass will be used | |
CssClass | String | The CSS class name to use when rendering the control (if the Error property is false) | |
CssClassError | String | The CSS class name to use when rendering the control (if the Error property is true) | |
AutoPost | Boolean | Setting this to true will render the attribute οnchange="this.form.submit()" | |
OnChange | String | Defines a line of javascript to execute when the control is changed on the client. The javascript will be prepended to the javascript generated by the AutoPost property | |
Enabled | Boolean | Setting this to false causes the control to be renderd with the disabled="disabled" attribute |
TextBoxControl
想这样的textbox<input type="text" />
属性:
Property | Type | Description | |
---|---|---|---|
Value | String | The text in the textbox | |
MaxLength | int | The maximum length of the text in the text box (maxlength attribute) | |
AutoComplete | bool | When set to false, the attribute autocomplete="off" will be rendered | |
OnKeyPress | string | Adds the specified javascript in the onkeypress attribute | |
OnKeyDown | string | Adds the specified javascript in the onkeydown attribute | |
OnKeyUp | string | Adds the specified javascript in the onkeyup attribute | |
DefaultCssClass | string | (static) Sets the default value for the CssClass property of all TextBoxControl instances | |
DefaultCssClassError | string | (static) Sets the default value for the CssClassError property of all TextBoxControl instances |
DropdownControl
像这样的dropdown<select>
属性:
Property | Type | Description | |
---|---|---|---|
Value | object | The currently selected value in the list | |
DataSource | object | A list of objects/values to bind to the control (explained below) | |
Items | List<DropdownControl.Item> | Contains all items in the list box (explained below) | |
KeyMember | string | The name of the field or property containing the unique key of the items in the dropdown control. When this property is not set, the object itself will be used as the key (useful when the DataSource is an array) | |
ValueMember | string | The name of the field or property containing the value (visible to the user) of the items in the dropdown control. When this property is not set, the object itself (converted to a string) will be used to display items in the dropdown list (useful when the DataSource is an array) | |
ShowBlank | Boolean | If set to true, a blank item will be added to the list (as the first item) | |
BlankKey | object | The value to store in the Value property when the blank item is selected | |
BlankValue | object | What to show in the dropdown control as the blank value | |
ValueFormatString | string | When set, a standard .NET format string will be used to show the items in the list. Use {0} for the key and {1} for the value | |
DefaultCssClass | string | (static) Sets the default value for the CssClass property of all DropdownControl instances | |
DefaultCssClassError | string | (static) Sets the default value for the CssClassError property of all DropdownControl instances |
Filling the dropdown list
这里有俩个属性来指定在控件种显示的内容:DataSource and Items。 使用规则如下:
1、如果你设置DataSource,就应该清除Item.这意味着你永远不能在操作Item列表之后再进行DataSource设置
2、当进行Item列表检索时,应该填充列表值。
3 、你可以随时添加和删除Item
Item列表的类型是list<item>,item有俩个属性:key,value
在处理返回值时,你不再需要重新填充列表值,只需要检索值的属性即可。
你可以在任何时候设置value属性,甚至在添加列表项到列表之前,列表项的匹配值在在视图呈现前完成,并不是在value属性设置的时候。 HiddenControl
像这样的Hidden控件<input type="hidden">
它只有一个属性:
Property | Type | Description | |
---|---|---|---|
Value | string | The value attribute of the cont |
CheckboxControl
像这样的 checkbox控件<input type="checkbox">
属性:
Property | Type | Description | |
---|---|---|---|
Checked | Boolean | True means the checkbox is checked | |
OnClick | String | Adds the specified javascript in the onclick attribute |
MemoControl
像这样的textarea控件<textarea>
属性:
Property | Type | Description | |
---|---|---|---|
Value | String | The text in the textbox | |
Width | Int32 | The width of the text box in characters (it's not recommended to be used, CSS styling is preferred) | |
Height | Int32 | The height of the text box in lines (it's not recommended to be used, CSS styling is preferred) | |
OnKeyPress | string | Adds the specified javascript in the onkeypress attribute | |
OnKeyDown | string | Adds the specified javascript in the onkeydown attribute | |
OnKeyUp | string | Adds the specified javascript in the onkeyup attribute |
RadioButtonControl
像这样的checkbox控件<input type="checkbox">
属性:
Property | Type | Description | |
---|---|---|---|
Checked | Boolean | True means the radio button is checked | |
Group | String | The group name for this radio button. Only one radio button can be checked per group | |
OnClick | String | Adds the specified javascript in the onclick attribute |
Built-in form field attributes
为了映射某个字段到某个控件上,你需要在这个字段上添加字段属性,这些我们已经在前面的章节讲过了,下面这些属性是可用的:
[FormTextBox]
To be completed
[FormDropdown]
To be completed
[FormPassword]
To be completed
[FormEMail]
To be completed
[FormHidden]
To be completed
[FormCheckbox]
To be completed
[FormDate]
To be completed
[FormMemo]
To be completed
[FormRadioButton]
To be completed