开发者

Multiple CSS classes in an html element ASP.NET MVC 3

开发者 https://www.devze.com 2023-03-24 02:22 出处:网络
I 开发者_JAVA技巧know it is possible to have multiple CSS classes in an element, but I was wondering if it was possible to select which class to use by using a razor if statement?

I 开发者_JAVA技巧know it is possible to have multiple CSS classes in an element, but I was wondering if it was possible to select which class to use by using a razor if statement?

So something like this (pseudo code)

<div @if( num items in Model ==0){
         class="Error";
       } else
        class ="home"; >

I would think that this would be possible, if anyone has some ideas I would appreciate their help!

Thanks in advance


<div class="@(Model.Count() == 0 ? "Error" : "home")">

But that looks ugly to me. I would probably write a custom HTML helper if I had to repeat this logic over my views.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号