Conditional Html attribute using razor

前端 未结 4 1731
故里飘歌
故里飘歌 2021-02-12 14:46

I have a situation where I want to display a button as being enabled or disabled depending on a property which has been set on the view model.

@if (Model.CanBeDe         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 15:30

    Do the check once and have the disabled property be determined by a temporary variable called enabled.

    @code
        var enabled = "disabled='disabled'";
        if(Model.CanBeDeleted)
        enabled = "";
        end code
        
    

提交回复
热议问题