vici mvc开发第八篇——Controls(控件)

一、Controls

通过前面的教程我们已经知道,vici mvc可以呈现一个绑定在某一个类中某个字段的控件,你只需要通过在某个字段上添加属性,告诉框架呈现哪个控件,这么呈现等。

你也可以明确的创建一个控件用来在视图里呈现,例如:

在视图中应该这么写:

二、Built-in controls

一般情况下所以的控件都有下列属性:

PropertyTypeDescription
Id StringThe 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 StringThe name of the control, which is required and should only be set by the constructor
Error BooleanIf 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 StringThe CSS class name to use when rendering the control (if the Error property is false)
CssClassError StringThe CSS class name to use when rendering the control (if the Error property is true)
AutoPost BooleanSetting this to true will render the attribute οnchange="this.form.submit()"
OnChange StringDefines 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 BooleanSetting this to false causes the control to be renderd with the disabled="disabled" attribute

TextBoxControl

想这样的textbox<input type="text" />

属性:

PropertyTypeDescription
ValueStringThe text in the textbox
MaxLengthintThe maximum length of the text in the text box (maxlength attribute)
AutoCompleteboolWhen set to false, the attribute autocomplete="off" will be rendered
OnKeyPressstringAdds the specified javascript in the onkeypress attribute
OnKeyDownstringAdds the specified javascript in the onkeydown attribute
OnKeyUpstringAdds the specified javascript in the onkeyup attribute
DefaultCssClassstring(static) Sets the default value for the CssClass property of all TextBoxControl instances
DefaultCssClassErrorstring(static) Sets the default value for the CssClassError property of all TextBoxControl instances

DropdownControl

像这样的dropdown<select>

属性:

PropertyTypeDescription
ValueobjectThe currently selected value in the list
DataSourceobjectA list of objects/values to bind to the control (explained below)
ItemsList<DropdownControl.Item>Contains all items in the list box (explained below)
KeyMemberstringThe 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)
ValueMemberstringThe 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)
ShowBlankBooleanIf set to true, a blank item will be added to the list (as the first item)
BlankKeyobjectThe value to store in the Value property when the blank item is selected
BlankValueobjectWhat to show in the dropdown control as the blank value
ValueFormatStringstringWhen 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
DefaultCssClassstring(static) Sets the default value for the CssClass property of all DropdownControl instances
DefaultCssClassErrorstring(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">

它只有一个属性:

PropertyTypeDescription
ValuestringThe value attribute of the cont

CheckboxControl

像这样的 checkbox控件<input type="checkbox">

属性:

PropertyTypeDescription
CheckedBooleanTrue means the checkbox is checked
OnClickStringAdds the specified javascript in the onclick attribute

MemoControl

像这样的textarea控件<textarea>

属性:

PropertyTypeDescription
ValueStringThe text in the textbox
WidthInt32The width of the text box in characters (it's not recommended to be used, CSS styling is preferred)
HeightInt32The height of the text box in lines (it's not recommended to be used, CSS styling is preferred)
OnKeyPressstringAdds the specified javascript in the onkeypress attribute
OnKeyDownstringAdds the specified javascript in the onkeydown attribute
OnKeyUpstringAdds the specified javascript in the onkeyup attribute

RadioButtonControl

像这样的checkbox控件<input type="checkbox">

属性:

PropertyTypeDescription
CheckedBooleanTrue means the radio button is checked
GroupStringThe group name for this radio button. Only one radio button can be checked per group
OnClickStringAdds 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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值