vici mvc開發第八篇——Controls(控件)

一、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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章