0

Im trying to create an Html Helper that renders blog posts from a database, but for some reason the HtmlHelper doesn't render the code..

This is what my helper looks like:

@helper Render(System.Web.Mvc.HtmlHelper html, T2L.Models.Post post, bool isAdmin, bool isMember)
{
    <p>dsfds</p>
    <div class="wrapper_top">
        <div class="grid_1 alpha">
            <div class="date">
                <span>
                    @post.time.ToString("MMM").ToUpper()

                </span>
                @post.time.ToString("dd")
            </div>
        </div>
        <div class="content span_2_of_single">
            <h5 class="blog_title"><a href="@Href("~/Blog/p/" + post.id)">@post.title</a></h5>
            <div class="content">
                <div class="span-1-of-1">
                    <a href="bloginner.html"><img class="m_img"  src="@post.thumbnail" alt=""/></a>
                </div>
                <div class="span-1-of-2">
                    <p>@post.body</p>

                    <a href="@Href("~/Blog/p/"+post.id)" class="arrow_btn">Read More</a>
                </div>
                <div class="clear"> </div>
            </div>  
            <div class="links">
                <h3 class="comments">By<a href="bloginner.html">@post.author</a></h3>
                <h3 class="comments"><a href="#">10 Comments</a></h3>
                <h3 class="tags">Tags: <a href="#">Design</a>,<a href="#">Creative</a>,<a href="#">wordpress theme</a></h3>
                <h3>Share</h3>
                <h3>
                    <div class="social_1">
                        <ul>    
                            <li class="icon1_t"><a href="#"><span> </span></a></li>
                            <li class="icon2_f"><a href="#"><span> </span></a></li>     
                        </ul>
                    </div>
                </h3>
                <div class="clear"> </div>
            </div>
        </div>
        <div class="clear"> </div>
    </div>
}

and this is how I call it:

   @if (Model.Count() == 0)
                {
                    <div class="wrapper_top">
                        <p style="font-size:22px; font-weight:bold; font-style:italic; color:#1d7abc;">No posts available..</p>
                    </div>
                }
                else
                {
                    foreach (Post post in Model)
                    {
                        PostGenerator.Render(Html, post, isAdmin, isMember);
                    }
                }

I don't see what I'm doing wrong exactly.. Can someone please help??

4
  • that's not usually how you make an HtmlHelper. Usually it's an extension method off an HtmlHelper object. It looks like what you're trying to do is define a Section or perhaps a Partial View Commented Apr 10, 2014 at 19:18
  • That's a View Helper indeed. Commented Apr 10, 2014 at 19:25
  • Yeah its a view helper, but it wont render.. i had it working a while ago but idk am i doing something wrong?? Commented Apr 10, 2014 at 19:26
  • You're missing the @ as @Floremin already answered. Commented Apr 10, 2014 at 19:28

1 Answer 1

4

Try adding @ in front of your call:

@PostGenerator.Render(Html, post, isAdmin, isMember)
Sign up to request clarification or add additional context in comments.

1 Comment

Sweeet! That did the trick! lol thw power of the "At" Symbol!

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.