I try to create a helper in my project. This is my code:
@using VrBlog.Models;
@helper Render(Post post, System.Web.Mvc.HtmlHelper html, bool isAdmin, bool showComments)
{
<div class="postTitle"><a href="@Href("~/Views/Posts/Details/" + post.Id)">@post.Title</a></div>
<div class="postContainer">
<div class="postTabs">
<div class="dateTab">
<div class="month">@post.DateTime.Value.ToString("MMM").ToUpper()</div>
<div class="day">@post.DateTime.Value.ToString("dd")</div>
</div>
<div class="commentsTab">
<a href="@Href("~/Views/Posts/Details/"+post.Id + "#comments")">@post.Comments.Count</a>
</div>
</div>
<div class="postContent">
<div class ="postBody">@html.Raw(post.Body)</div>
<div class="tagList">
@foreach (Tag tag in post.Tags)
{
<span class="tag"><a href="@Href("~/Views/Posts/Tags" + tag.Name)">@tag.Name</a></span>
}
</div>
<div class="linkList">
@{ string url = "http://www.mattblagden.com/posts/details/" + post.Id;}
</div>
</div>
</div>
if (showComments)
{
<div id="commentsContainer">
<a id ="comments"></a>
@foreach (Comment comment in post.Comments.OrderBy(x => x.DateTime))
{
<div class="comment">
<div class="commentName">
@if (!string.IsNullOrWhiteSpace(comment.Email))
{
<a href="mailto:@comment.Email">@comment.Name</a>
}
else
{
@comment.Name;
}
</div>
said:
<div class="commentBody">@html.Raw(html.Encode(comment.Body).Replace("\n", "<br/>"))</div>
<div class="commentTime">at @comment.DateTime.Value.ToString("HH:mm") on @comment.DateTime.Value.ToString("yyyy/MM/dd")</div>
</div>
}
<div id="commentEditor">
<div id="commentPromt">Leave a comment!</div>
<form action="@Href("~/Views/Posts/Comment/" + post.Id)" method="post">
<input type="text" id="commentNamePromt" name="name"/>Name (required)<br/>
<input type="text" id="commentEmailPromt" name="email" />Email (optional)<br/>
<textarea id="commentBodyInput" name="body" rows="10" cols="60"></textarea><br/>
<input type="submit" id="commentSubmitInput" name="submit" value="Submit!"/>
</form>
</div>
</div>
}
}
And after this, I try to call it from the view. My helper is in the AppCode
folder inside the project.
I try to call it like this
@foreach (Post post in Model)
{
@PostHelper.Render(post,Html,isAdmin, false)
}
But I get the following error:
Error CS0103 The name 'PostHelper' does not exist in the current context
How I can fix this and why it not visible?