要在品牌名称前显示一批型号,例如:
我已经使用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>
}我在Model 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;
}如何在Modeal Public static中调用foreach函数
发布于 2016-12-21 07:21:53
您必须从Razor视图调用您的方法:
<span class="badge badge-info">@YourClass.Count(item.Name)</span></a>https://stackoverflow.com/questions/41257077
复制相似问题