我们可以使用@attributes标签对多属性值赋值进行简化,通过一个字典直接进行赋值,这个功能毕竟简单,我们直接用代码来做示例。
@page "/demoPage"
@rendermode InteractiveAuto
<h3>DemoPage</h3>
<form>
<div>
<label>姓名</label>
<input placeholder=@placeholder
class=@classStr
style=@style/>
</div>
</form>
@code {
private string style = "width:300px";
private string classStr = "form-control";
private string placeholder = "请输入姓名";
}
效果如下:
@page "/demoPage"
@rendermode InteractiveAuto
<h3>DemoPage</h3>
<form>
<div>
<label>姓名</label>
<input @attributes=@attributes/>
</div>
</form>
@code {
private Dictionary<string, object> attributes = new(){
{"style","width:300px" },
{"class","form-control" },
{"placeholder","请输入姓名" },
};
}
效果如下:
我们可以看到效果没有变化,代码别的更简洁了,直接绑定Dictionary<string, object> attributes就可以完成属性的赋值
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有