shark6552
shark6552

Reputation: 101

why the name does not exist in the current category?

Trying to generate same code of block with a loop but getting this problem.

Inside the foreach loop the first time I use the var categories I have no problem or error but the second time inside the IMG tag it says "the name does not exist in the current category"

However if I put another tag (a, img , p etc ) after the foreach and before the div with class col-md-4 , then all other uses of var categories is giving the same error "the name does not exist in the current category"

why?

@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>

Upvotes: 0

Views: 114

Answers (1)

CodeConstruct
CodeConstruct

Reputation: 414

@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>
}

Upvotes: 1

Related Questions