user3223507 user3223507 - 3 months ago 8
C# Question

Output csharp into a html class

Trying to acheive outputing a variable from csharp into the class of a html element.

Currently i'm doing this:

@foreach (var cocktail in Model)
{



<li>
<div class="drink">
<div class="drink-sprite " ></div>
</div>
<div class="details">
<div class="name">@cocktail.CocktailName</div>
<div class="price">£@cocktail.Price.ToString("0.00")</div>
<div class="description">@cocktail.Description</div>
</div>
</li>

}


essentially in the div class="drink-sprite" I want to put the drink type in the glass so an image is shown based on the class types. so drink-sprite martini - which is dervied from cocktail.type.

Anythoughts?

Answer
@foreach (var cocktail in Model)
{
    <li>
        <div class="drink">
            <div class="drink-sprite @cocktail.Type"></div>
        </div>
        <div class="details">
            <div class="name">@cocktail.CocktailName</div>
            <div class="price">£@cocktail.Price.ToString("0.00")</div>
            <div class="description">@cocktail.Description</div>
        </div>
    </li>
}