I have been searching high and low for a solution to this issue, but so far, no luck. If it has already been addressed elsewhere, I apologize.
Here is the code snippet I am currently working with:
@{
foreach (var item in Model.Activities)
{
<div class="col-md-4 col-lg-4 col-sm-6 col-xs-12 over-f-hidden">
<div class="block-main">
<div class="block-inner green">
<br />
<h5>@item.ActivityName</h5>
<h4><span><a href="@Url.Action("ScanRequest","Home",new { id = item.id })" style="text-decoration: none">SELECT THIS ACTIVITY</a></span></h4>
<br />
</div>
</div>
</div>
}
}
Furthermore, I have three CSS classes named:
.red
.green
.yellow
Within my code, for the class "block-inner green", I want to replace "green" with a randomly selected class from my pool of three classes. It's okay if there is repetition.
Elsewhere in the View's body, I have added the following:
@{
string[] color = { "red", "yellow", "green" };
}
However, I am unsure of how to utilize a random element from that array as a class for the div using Razor.
Is there a way to achieve this exclusively within the View?
Thank you in advance for any guidance you can offer.