相同的 foreach 循环我已经发布了好几天了 :) 我快完成了 :)
我现在需要设置不同的显示和隐藏帖子的样式,这样如果它们是“隐藏”的,它们就需要是红色的。所以我研究并且可以在 CSS 中使用类来实现。谁能建议如何整理 if 语句?
@foreach
(var post in Model.tb_SH_Forum_Posts.OrderBy(o => o.Post_Date))
{
using (Html.BeginForm("Hide", "Post", new { id = post.Post_ID }))
{
<input type="submit" name = "hidePosts" value="Hide" />
}
using (Html.BeginForm("Show", "Post", new { id = post.Post_ID }))
{
<input type="submit" name = "showPosts" value="Show" />
}
伪
如果 private_id = 2
<div class ="HIDE">
<fieldset>
<p class="post_details">At @post.Post_Date By @(post.Anon == true ? "Anonymous" : post.Username)
</p>
@post.Post_Desc
</fieldset>
</div>
其他
<div class ="SHOW">
<fieldset>
<p class="post_details">At @post.Post_Date By @(post.Anon == true ? "Anonymous" : post.Username)
</p>
@post.Post_Desc
</fieldset>
</div>
}
一如既往,感谢您的时间/指导
最佳答案
试试这个:
<div <%: private_id == 2 ? "class=HIDE" : "class=SHOW" %> >
关于css - ASP.NET MVC3 C# - 按条件的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078153/