MVC razor html忽略href属性

时间:2015-08-04 08:10:47

标签: c# asp.net-mvc razor asp.net-mvc-5

以下代码执行正常

  @foreach (var item in Model.SubCategories)
                {
                    <div class="item-box">
                        <div class="sub-category-item">
                            <h2 class="title">
                                <a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
                                    @item.Name
                                </a>
                            </h2>
                        </div>
                    </div>
                }

这也有效

@foreach (var item in Model.SubCategories)
                {
                    <div class="item-box">
                        <div class="sub-category-item">
                            <h2 class="title">
                                <text>@item.SeName</text>                                    
                                @*<a href="@Url.RouteUrl("Category", new { SeName = item.SeName })" title="@item.PictureModel.Title">
                                    @item.Name
                                </a>*@
                            </h2>                               
                        </div>
                    </div>
                }

但是当我想用简单的href属性编写相同的代码时,VS会忽略该行。我甚至无法在线上设置一个断点。难道我做错了什么?

 @foreach (var item in Model.SubCategories)
                {
                    <div class="item-box">
                        <div class="sub-category-item">
                            <h2 class="title">
                                <a href="@item.SeName" title="@item.PictureModel.Title" />
                            </h2>
                        </div>
                    </div>
                }

1 个答案:

答案 0 :(得分:2)

添加链接文字:

 @foreach (var item in Model.SubCategories)
 {
     <div class="item-box">
         <div class="sub-category-item">
             <h2 class="title">
                 <a href="@item.SeName" title="@item.PictureModel.Title">@item.PictureModel.Title</a>
             </h2>
         </div>
     </div>
 }