要顯示模型的數量在品牌名稱的前面,如:如何在MVC中顯示的產品搜索品牌搜索引擎數4
- 諾基亞(10)
- 電話(20 )
我有使用foreach
tobind一個品牌名稱的數據。下面的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>
}
我已經做了在型號public static int Count
一個代碼,我想從<span class="badge badge-info">4</span>
調用,並與4的結果替換計數的代碼。下面是靜態代碼
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;
}
我如何可以調用foreach
的Modeal Public static
功能?
@(MyClass.Count(item.Name))? – misha130