我无法使用telerik工作我的网格
这是我的代码:
MODEL
public class Office
{
public int OfficeID { get; set; }
public string OfficeName { get; set; }
public string OfficeAddress { get; set; }
}
视图模型
public class OfficeViewModel
{
public int OfficeID { get; set; }
public string OfficeName { get; set; }
public string OfficeAddress { get; set; }
}
查看
@(Html.Telerik().Grid<Office>()
.Name("Offices")
.ToolBar(tb => tb.Insert())
.DataBinding(binding => binding.Ajax()
.Select("GetOffice", "Office")
.Update("UpdateOffice", "Office")
.Insert("InsertOffice", "Office")
.Delete("DeleteOffice", "Office"))
.DataKeys(keys => keys.Add(o => o.OfficeID))
.Columns(cols =>
{
cols.Bound(c => c.OfficeID).ReadOnly();
cols.Bound(c => c.OfficeName).Width(20);
cols.Bound(c => c.OfficeAddress).Width(70);
cols.Command(cmd =>
{
cmd.Edit();
cmd.Delete();
});
})
)
CONTROLLER
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
[GridAction]
public ActionResult GetOffices()
{
return View(new GridModel(GetOfficeViewModels()));
}
private IQueryable<OfficeViewModel> GetOfficeViewModels()
{
return db.Offices
.Select(
c => new OfficeViewModel
{
OfficeID = c.OfficeID,
OfficeName = c.OfficeName,
OfficeAddress = c.OfficeAddress
});
}
最后,布局。
<li>@Html.ActionLink("Office", "Index", "Office")</li>
请帮我解决这个问题,我已经花了很多时间在这上面。我只是一个初学者:(
由于
答案 0 :(得分:1)
现在已修复,应该是
.Select("GetOffices", "Office")
我错过了's',抱歉我是这个telerik的新手
由于