How to add a second css class with a conditional value in razor MVC 4

后端 未结 4 854
傲寒
傲寒 2021-01-30 02:32

While Microsoft has created some automagic rendering of html attributes in razor MVC4, it took me quite some time to find out how to render a second css class on an element, bas

4条回答
  •  感情败类
    2021-01-30 03:10

    I believe that there can still be and valid logic on views. But for this kind of things I agree with @BigMike, it is better placed on the model. Having said that the problem can be solved in three ways:

    Your answer (assuming this works, I haven't tried this):

    Second option:

    @if (Model.Details.Count > 0) {
        
    } else {
    }

    Third option:

    0 ? "show" : "hide"))">

提交回复
热议问题