Set disable attribute based on a condition for Html.TextBoxFor

后端 未结 12 1132
清酒与你
清酒与你 2020-11-28 06:13

I want to set disable attribute based on a condition for Html.TextBoxFor in asp.net MVC like below

@Html.TextBoxFor(model => model.ExpireDate, new { style         


        
12条回答
  •  清酒与你
    2020-11-28 06:50

    if you dont want to use Html Helpers take look it my solution

    disabled="@(your Expression that returns true or false")"
    

    that it

    @{
        bool isManager = (Session["User"] as User).IsManager;
    }
    
    

    and I think the better way to do it is to do that check in the controller and save it within a variable that is accessible inside the view(Razor engine) in order to make the view free from business logic

提交回复
热议问题