Here is my action code
public class personnelViewModel{
public Guid PKPersonelID { get; set; }
public string name { get; set; }
public string family { get; set; }
public int usageCount { get; set; }
}
var model = from personnel in DB.RFH_Personnel select new personnelViewModel
{
PKPersonelID = personnel.PKPersonelID,
name = personnel.Name,
family = personel.Family
}
freach(var item in model)
item.usageCount = DB.RFH_Service.Count(d => d.FKPersonelID == item.PKPersonelID);
return View(model);
and this is my view:
@model IEnumerable<RefahiWeb.Models.personnelViewModel>
@{
var grid = new WebGrid(source: Model, rowsPerPage: 15, canPage: true, canSort: true);
}
@grid.GetHtml(tableStyle: "table tablesorter table-bordered table-hover request-status",
mode: WebGridPagerModes.All,
columns: grid.Columns(
grid.Column("name", "name", canSort: false),
grid.Column("family", "family", canSort: false),
grid.Column("usageCount", "usageCount", canSort: false)
)
)
the problem is that usageCount is always set to zero and the value that is set in froeach loop does not change the value of usageCount. Any help is appreciated in advance.