Razor MVC未封闭标签

时间:2016-08-23 13:43:01

标签: html asp.net-mvc razor tags

出于某种原因,我无法关闭li标签,我在代码

中添加了li标签有问题的评论
<ul>
    @foreach (var item in @ViewBag.kategorije) {
    <li>
        <a href="/category/@HttpUtility.UrlEncode(item.Name)/@item.CategoryID">@item.Name</a> @if (item.ChildCategory.Count > 0) { foreach (var child in item.ChildCategory) {
        <li class="child">
            <a href="/category/@HttpUtility.UrlEncode(child.Name)/@child.CategoryID">@child.Name</a>
        </li>
        } }
    </li>
    <!-- it says this tag has no matching start tag -->
    }
</ul>

1 个答案:

答案 0 :(得分:0)

哎呀,发现它,我需要将子列表元素嵌入到新的ul,基本的html错误中

<ul>
                    @foreach (var item in @ViewBag.kategorije)
                    {
                        <li>

                            <a href="/category/@HttpUtility.UrlEncode(item.Name)/@item.CategoryID">@item.Name</a>


                            if (item.ChildCategory.Count > 0)
                            {  <ul>
                                foreach (var child in item.ChildCategory)
                                {
                                <li class="child">
                                    <a href="/category/@HttpUtility.UrlEncode(child.Name)/@child.CategoryID">@child.Name</a>
                                </li>
                                }
                            </ul>
                            }
                        </li>

                    }
                </ul>