如何在MVC htmlAttribute集禁用 [英] How to set disabled in MVC htmlAttribute

查看:102
本文介绍了如何在MVC htmlAttribute集禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用HTML助手,什么是设置基于一个条件的属性的最佳方法。例如:

When using an HTML Helper, what is the best method to set an attribute based on a condition. For example

<%if (Page.User.IsInRole("administrator")) {%>
<%=Html.TextBoxFor(m => m.FirstName, new {@class='contactDetails'}%>
<%} else {%>
<%=Html.TextBoxFor(m => m.FirstName, new {@class='contactDetails', disabled = true}%>
<%}%>

必须有一个更好的办法只有一个额外的密钥对编程方式添加到匿名类型?不能使用

There must be a better way to programmatically add just one additional KeyPair to the anonymous type? Can't use

new { .... disabled = Page.User.IsInRole("administrator") ... }

在浏览器采取任何禁用的属性值,使得输入禁用

as the browser takes any disabled attribute value as making the input disabled

推荐答案

我可以建议你使用mvccontrib.FluentHtml。

I could suggest you to use mvccontrib.FluentHtml.

您可以做这样的事情。

 <%=this.TextBox(m=>m.FirstNam ).Disabled(Page.User.IsInRole("administrator"))%>

这篇关于如何在MVC htmlAttribute集禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆