Asp.net 使用HTML.Raw和li解析错误?
我的ASP.NET MVC网站中有以下代码:Asp.net 使用HTML.Raw和li解析错误?,asp.net,html,asp.net-mvc,razor,Asp.net,Html,Asp.net Mvc,Razor,我的ASP.NET MVC网站中有以下代码: @foreach (var item in Model.Comments.Where(c=>c.CommentId == Model.CurrentNode)) { if(Model.Level == 0){ @Html.Raw("<li style=\"border:none;\">") } else { @Html.Raw("<li>") }
@foreach (var item in Model.Comments.Where(c=>c.CommentId == Model.CurrentNode))
{
if(Model.Level == 0){
@Html.Raw("<li style=\"border:none;\">")
}
else
{
@Html.Raw("<li>")
}
@foreach(Model.Comments.Where(c=>c.CommentId==Model.CurrentNode)中的变量项)
{
如果(Model.Level==0){
@Html.Raw(“”)
}
其他的
{
@Html.Raw(“ ”)
}
尝试访问此页面时,我遇到以下异常:
分析器错误消息:遇到没有匹配开始标记的结束标记“li”。您的开始/结束标记是否正确平衡?
我尝试了很多不同的选择,但都无法实现
编辑1:
@if (!Model.CurrentNode.HasValue)
{
@Html.Raw("<div class=\"comment-root\" id=\"comment-root\">")
@*hid911 Tells what voteKey to use for this section*@
<input pid="hidVoteKey" type="hidden" value="1" />
}
<ul class="commentList sub">
@foreach (var item in Model.Comments.Where(c=>c.CommentId == Model.CurrentNode))
{
if(Model.Level == 0){
<li style="border:none;">
}
else
{
<li>
}
@if(!item.Deleted)
{
<div class="commentBack">
@if (Request.IsAuthenticated && uFeed.Handlers.AccountHandler.UserContextInstance.Id != item.CreatedBy.Id)
{
@Html.Partial("VotePartial", item.VoteViewModel)
}
else
{
<div style="float:left; width: 30px; "> </div>
}
<div class ="floatLeft" style="width: 90%">
<div class="CommentHeader" id="commentHeader-@item.Id">
<p class="Timestamp dimText">
@Html.ActionLink(item.CreatedBy.Text, "User/" + item.CreatedBy.Text, "Post")
| @item.VoteBalance poäng |
@Html.GetDisplayDate(item.CreatedDate)
</p>
</div>
<div id="commenttext-@item.Id" class="commentText">
@item.Text
</div>
<div id="comment-@item.Id" class="CommentFooter">
@if (Request.IsAuthenticated)
{
<div class="floatLeft">
@Html.ActionLink("Svara", string.Empty, null, new { id= "respond-" + item.Id, href = "#comment", @class = "respond" })
</div>
}
@if (Request.IsAuthenticated && uFeed.Handlers.AccountHandler.UserContextInstance.Id ==item.CreatedBy.Id)
{
<div class="floatLeft" id="divremove-@item.Id">
- @Html.ActionLink("Editera", string.Empty, null, new { id= "edit-" + item.Id, href = "#comment", @class = "edit" })
- @Html.ActionLink("Ta bort", string.Empty, null, new { id="remove-"+item.Id, @class = "remove"})
</div>
<div class="floatLeft hidden" id="divconfirmremove-@item.Id"> - Ta bort?
@Html.ActionLink("Ja", string.Empty, null, new { id = "confirm-remove-yes-" + item.Id, @class = "confirm-remove-yes" })
/
@Html.ActionLink("Nej", string.Empty, null, new { id = "confirm-remove-no-" + item.Id, @class = "confirm-remove-no" })
</div>
}
@if(Model.Comments.Any(c=>c.CommentId == item.Id))
{
@Html.Raw(" - ")
@Html.ActionLink("Dölj kommentarer", string.Empty, null, new { id = "toggle-" + item.Id, Href = "#togglecomments", @class = "toggle active" })
}
<div style="clear:both;"></div>
</div>
</div>
<div style="clear:both;"></div>
</div>
}
else
{
<div class="commentBack">
<div style="float:left; width: 30px; height: 30px"> </div>
<div style="float:left">
<div class="commentText" ><i>[Borttagen]</i></div>
<div id="comment-@item.Id" class="CommentFooter">
@if(Request.IsAuthenticated)
{
<div class="floatLeft">
@Html.ActionLink("Svara", string.Empty, null, new { id= "respond-" + item.Id, href = "#comment", @class = "respond" })
</div>
}
@if(Model.Comments.Any(c=>c.CommentId == item.Id))
{
@Html.Raw(" - ")
@Html.ActionLink("Dölj kommentarer", string.Empty, null, new { id = "toggle-" + item.Id, Href = "#togglecomments", @class = "toggle active" })
}
</div>
</div>
<div style="clear:both;"></div>
</div>
}
<div id="comments-for-@item.Id" class="CommentContainer">
@Html.Partial("CommentPartial", new uFeed.Views.ViewModels.CommentTreeItemViewModel(item.Id, Model.Comments, Model.Level + 1))
</div>
<div style="clear:both;"></div>
</li>
}
</ul>
@if(!Model.CurrentNode.HasValue)
{
@Html.Raw(“”)
@*hid911告诉voteKey在本节中使用什么*@
}
@foreach(Model.Comments.Where(c=>c.CommentId==Model.CurrentNode)中的var项)
{
如果(Model.Level==0){
-
}
其他的
{
-
}
@如果(!item.Deleted)
{
@if(Request.IsAuthenticated&&uFeed.Handlers.AccountHandler.UserContextInstance.Id!=item.CreatedBy.Id)
{
@Html.Partial(“VotePartial”,item.VoteViewModel)
}
其他的
{
}
@ActionLink(item.CreatedBy.Text,“User/”+item.CreatedBy.Text,“Post”)
|@item.VoteBalance poäng|
@Html.GetDisplayDate(item.CreatedDate)
@项目.案文
@如果(请求已验证)
{
@ActionLink(“Svara”,string.Empty,null,new{id=“respond-”+item.id,href=“#comment”,@class=“respond”})
}
@if(Request.IsAuthenticated&&uFeed.Handlers.AccountHandler.UserContextInstance.Id==item.CreatedBy.Id)
{
-@Html.ActionLink(“Editera”,string.Empty,null,new{id=“edit-”+item.id,href=“#comment”,@class=“edit”})
-@Html.ActionLink(“Ta bort”,string.Empty,null,new{id=“remove-”+item.id,@class=“remove”})
-塔博特?
@ActionLink(“Ja”,string.Empty,null,new{id=“confirm remove yes-”+item.id,@class=“confirm remove yes”})
/
@ActionLink(“Nej”,string.Empty,null,new{id=“confirm remove no-”+item.id,@class=“confirm remove no”})
}
@if(Model.Comments.Any(c=>c.CommentId==item.Id))
{
@Html.Raw(“-”)
@ActionLink(“Dölj kommentarer”,string.Empty,null,new{id=“toggle-”+item.id,Href=“#togglecomments”,@class=“toggle active”})
}
}
其他的
{
[博特根]
@如果(请求已验证)
{
@ActionLink(“Svara”,string.Empty,null,new{id=“respond-”+item.id,href=“#comment”,@class=“respond”})
}
@if(Model.Comments.Any(c=>c.CommentId==item.Id))
{
@Html.Raw(“-”)
@ActionLink(“Dölj kommentarer”,string.Empty,null,new{id=“toggle-”+item.id,Href=“#togglecomments”,@class=“toggle active”})
}
}
@Html.Partial(“CommentPartial”,新的uFeed.Views.ViewModels.CommentTreeItemViewModel(item.Id,Model.Comments,Model.Level+1))
}
您不需要Html.Raw,因为您实际上没有输出包含Html的代码变量。这应该可以正常工作:
@foreach (var item in Model.Comments.Where(c=>c.CommentId == Model.CurrentNode))
{
if(Model.Level == 0){
<li style="border:none;">
}
else
{
<li>
}
@foreach(Model.Comments.Where(c=>c.CommentId==Model.CurrentNode)中的变量项)
{
如果(Model.Level==0){
}
其他的
{
}
你可能会进一步简化这个
@foreach (var item in Model.Comments.Where(c=>c.CommentId == Model.CurrentNode))
{
<li @(Model.Level == 0 ? "style=\"border:none;\"" : "")>
@foreach(Model.Comments.Where(c=>c.CommentId==Model.CurrentNode)中的变量项)
{
谢谢,但这不起作用,我在您的代码中遇到以下异常:foreach块缺少一个结束“}”字符。请确保此块中的所有“{”字符都有一个匹配的“}”字符,并且“}”字符都没有被解释为marku