user14224611
user14224611

Reputation:

How to store a couple of products in a loop and display it in a html page? with C#

to explain my question I want to display a couple of products in a product box in a html page. I do not want to write a specifed products in the html page. I want to set an array with loop to display a diffenet products each time.
For example:


<img src={{productImg}}>
<h2>{{productName}}</h2>
<p>{{productDescription}}</p>
<label>{{productPrice}}</label>

Upvotes: 1

Views: 138

Answers (1)

persian-theme
persian-theme

Reputation: 6638

example asp mvc:

@foreach (var item in Model.productList)
{
    <div class="row">
       <div class="col-md-2"><span>@item.ProductName</span></div>
       <div class="col-md-2"><span>@item.Price</span></div>
       <div class="col-md-4">
         @if (!string.IsNullOrEmpty(item.ProductPhoto))
         {
            <img src='@Url.Content(item.ProductPhoto)' />
         }
       </div>
    </div>
}

for asp webforms:

<% foreach(var item in productList) { %>
 <div class="row">
     <div class="col-md-2"><span><% item.ProductName %></span></div>
     <div class="col-md-2"><span><% item.Price %></span></div>
     <div class="col-md-4">
        <img src='<% if(!string.IsNullOrEmpty(item.ProductPhoto)){item.ProductPhoto} %>' />
     </div>
 </div>
<% } %>

Upvotes: 1

Related Questions