Reputation: 71
Same foreach loop I have been posting about for days :) I'm almost done :)
I now need to style the differing show and hide posts so that if they are 'hide' they need to be red. So I research and I can to that in CSS with classes. Can anybody advise how to sort out an if statement?
@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" />
}
PSEUDO
if 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>
ELSE
<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>
}
As always, thank you for your time/guidance
Upvotes: 1
Views: 396
Reputation: 8022
Ideally, you would like to create an HTML helper to handle that, since no logic should be used in Views.
http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs
Here is a Microsoft's article about custom helpers. Basically it's a class, where you pass something from the view, and then you include all the logic in there, and return something back to your view.
Upvotes: 0
Reputation: 2976
@if (private_id == 2)
{
<div class ="HIDE">
}else
{
<div class ="SHOW">
}
Upvotes: 1
Reputation: 9027
Try this:
<div <%: private_id == 2 ? "class=HIDE" : "class=SHOW" %> >
Upvotes: 1