0
這裏是我的動作代碼改變字段的值不會生效
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);
,這是我的看法:
@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)
)
)
問題是,usageCount總是被設置爲零和價值在froeach循環中設置的值不會更改usageCount的值。提前感謝任何幫助。
看起來像你有一些錯字,'item.usageHistory'應該是'item.usageCount'? –
這是輸入錯誤。我編輯了這個問題。 – Beginner