我正在尝试使用动态列实现一个模型。
我的模特:
public partial class AccountViewModel : DbContext
{
public ACCOUNT Accountdt { get; set; }
}
我的控制器代码返回index.cshtml:
// To display grid in Kendo UI
public ActionResult Accounts_Read([DataSourceRequest]DataSourceRequest request)
{
Json(GetAccounts().ToDataSourceResult(request,ModelState));
}
//To extract data from linq
private IEnumerable<Object> GetAccounts()
{
var database = new Entities();
var load = database.ACCOUNTs.AsQueryable();
AccountViewModel avm = new AccountViewModel();
return load.Select(account => avm.Accountdt);
}
我无法在结果数据网格中看到数据集。早期在模型中声明列时工作正常。
这是我的代码工作正常:
public partial class AccountViewModel : DbContext
{
public string Id { get; set; }
}
// To display grid in Kendo UI
public ActionResult Accounts_Read([DataSourceRequest]DataSourceRequest request)
{
Json(GetAccounts().ToDataSourceResult(request, ModelState));
}
private IEnumerable<Object> GetAccounts()
{
var database = new Entities();
var load = database.ACCOUNTs.AsQueryable();
return load.Select(account => AccountViewModel {
id = account.id;
});
}
答案 0 :(得分:0)
更改以下代码,
return load.Select(account => avm.Accountdt);
如下,
return load.Select(account => new AccountViewModel {
Accountdt = account
});