【问题标题】:why the name does not exist in the current category?为什么当前类别中不存在该名称?
【发布时间】:2016-06-19 01:08:13
【问题描述】:

尝试使用循环生成相同的块代码但遇到此问题。

我第一次使用 var 类别时在 foreach 循环中没有问题或错误,但第二次在 IMG 标记中显示“当前类别中不存在该名称”

但是,如果我在 foreach 之后和带有 col-md-4 类的 div 之前放置另一个标签(a、img、p 等),那么 var 类别的所有其他用途都会给出相同的错误“名称不存在在当前类别中”

为什么?

@model IEnumerable<MyAPP.Models.Category>
@{
    ViewBag.Title = "Index";
}

<div class="row">

    @foreach (var categories in Model)

           <div class="col-md-4">
                <h2>@Url.Action("Browse", new { categories = categories.CategoryName })</h2>
                <img src="@categories.ImagePath" class="img-responsive" alt="horizontal blids" />
                <p>
                    just text
                </p>
                <p><a class="btn btn-default" href="#">Learn more &raquo;</a></p>
            </div>

【问题讨论】:

  • foreach 循环的{} 大括号在哪里?
  • 可能缺少大括号,还要提防class@class
  • 感谢 Khosla 是的,这就是我错过了 {} 我正要发布答案但看到你的问题的问题。

标签: c# html asp.net asp.net-mvc html-helper


【解决方案1】:
@model IEnumerable<MyAPP.Models.Category>
@{
    ViewBag.Title = "Index";
}

<div class="row">

    @foreach (var categories in Model)
{
           <div class="col-md-4">
                <h2>@Url.Action("Browse", new { categories = categories.CategoryName })</h2>
                <img src="@categories.ImagePath" class="img-responsive" alt="horizontal blids" />
                <p>
                    just text
                </p>
                <p><a class="btn btn-default" href="#">Learn more &raquo;</a></p>
            </div>
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 2014-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多