Reputation: 61
Want to show a count of Models in front of Brand Name like :
- Nokia (10)
- Phone (20)
I have use a foreach
tobind a Brand Name Data. Below is a code of foreach
@foreach (var item in this.Model.CompanyList)
{
<li><a href="javascript:void(0);" style="padding-top: 2px; padding-bottom: 2px;">
<input type="checkbox" name="chkbrand" id="chkbrand" value="@item.Brand"/>
@item.Brand <span class="badge badge-info">4</span></a>
</li>
}
I have done a code in Model public static int Count
which I want to call from <span class="badge badge-info">4</span>
and replace a count with 4 with the result. Below is the static code
public static int Count(string Company)
{
int count = 0;
using (var db = new Entities())
{
count = (from o in db.Models
where o.Brand == Company
from t in o.Name
select t).Count();
}
return count;
}
How can I call the Modeal Public static
function in foreach
?
Upvotes: 0
Views: 483
Reputation: 2594
You have to call your method from your Razor view :
<span class="badge badge-info">@YourClass.Count(item.Name)</span></a>
Upvotes: 2