How to set disabled in MVC htmlAttribute

后端 未结 8 2397
刺人心
刺人心 2020-12-30 02:06

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\")) {%&g         


        
8条回答
  •  情书的邮戳
    2020-12-30 02:27

    You may also define this param that way:

    Page.User.IsInRole("administrator")
      ? (object)new { @class='contactDetails'} 
      : (object)new { @class='contactDetails', disabled = true}
    

提交回复
热议问题