1

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

3 Answers 3

1

Try this:

<div <%: private_id == 2 ? "class=HIDE" : "class=SHOW" %> >
Sign up to request clarification or add additional context in comments.

Comments

1
    @if (private_id == 2)
    {
        <div class ="HIDE">
    }else
    {
        <div class ="SHOW">
    }

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.