How to disable a button more elegantly

前端 未结 8 873
面向向阳花
面向向阳花 2020-12-14 16:46

I have on one of my views the following razor code:

@if (item.PMApproved != true) {
                    

        
8条回答
  •  暖寄归人
    2020-12-14 17:26

    A markup-centric solution aided by a new extension method:

    public static class HtmlExtensions
    {
       public static HtmlString DisabledIf(this HtmlHelper html, bool condition)
       {
          return new HtmlString(condition ? "disabled=\"disabled\"" : "");
       }
    }
    

    In your views, reuse out the wazoo:

    
    

    Nicely reusable, and the rendered markup is very clean with regards to whitespace:

    
    

提交回复
热议问题