Ich versuche, einen Helfer in meinem Projekt zu erstellen. Dies ist mein Code:Helper funktioniert nicht (ASP.NET MVC)
@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>
}
}
Und nach diesem, ich versuche, es aus der Sicht zu nennen. Mein Helfer ist im Ordner AppCode
im Projekt.
Ich versuche es wie dieses aber ich
@foreach (Post post in Model)
{
@PostHelper.Render(post,Html,isAdmin, false)
}
rufen Sie die folgende Fehlermeldung:
Error CS0103 The name 'PostHelper' does not exist in the current context
Wie ich dieses Problem beheben kann und warum es nicht sichtbar?
Sie meinen Paste Code von Helfer in View? @mjwills –
Mögliches Duplikat von [MVC Razor Helfer existiert nicht im aktuellen Kontext] (https://stackoverflow.com/questions/12601204/mvc-razor-helper-does-not-exist-in-current-context) – mjwills
Lassen Sie den '@ PostHelper' aus. – CodeCaster