在MVC4视图中唯一命名Javascript剑道对象
我试图在从同一控制器加载的同一部分视图中加载多个剑道网格。显示的网格数是动态的-取决于用户选择 问题是HTML页面中网格的所有实例化都显示相同的数据集,即与上次加载的网格对应的数据集。我认为这是因为网格都有相同的名称:在MVC4视图中唯一命名Javascript剑道对象,javascript,asp.net-mvc,asp.net-mvc-4,kendo-ui,kendo-grid,Javascript,Asp.net Mvc,Asp.net Mvc 4,Kendo Ui,Kendo Grid,我试图在从同一控制器加载的同一部分视图中加载多个剑道网格。显示的网格数是动态的-取决于用户选择 问题是HTML页面中网格的所有实例化都显示相同的数据集,即与上次加载的网格对应的数据集。我认为这是因为网格都有相同的名称: @(Html.Kendo().Grid<RegistrationManagement.Models.Member>() .Name("Grid") .Columns(columns => { columns.Bound
@(Html.Kendo().Grid<RegistrationManagement.Models.Member>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.LastName);
columns.Bound(p => p.FirstName);
columns.ForeignKey(p => p.MemberStatusID,
(System.Collections.IEnumerable)ViewData["status"], "Value", "Text");
columns.Bound(p => p.RegistrationYear);
columns.Bound(p => p.StreetAddress1);
columns.Bound(p => p.StreetAddress2);
columns.Bound(p => p.State);
columns.Bound(p => p.ZipCode);
columns.Bound(p => p.Email);
columns.Bound(p => p.PhoneNumber);
columns.Command(command => { command.Custom("Edit2").Click("CustomEdit");
command.Edit(); command.Destroy(); }).Width(160);
})
.ToolBar(toolbar => toolbar.Create())
// .Editable(editable => editable.Mode(GridEditMode.InCell))
.Editable()
.Groupable()
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Batch(true)
.ServerOperation(true)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(p => p.Id);
model.Field(p => p.MemberStatus).Editable(false);
})
.Read(read => read.Action("Grid_Member_Read", "Member", new { ClubID = @ViewBag.ClubID }))
.Create(update => update.Action("Grid_Member_Create", "Member", new { ClubID = @ViewBag.ClubID }))
.Update(update => update.Action("Grid_Member_Update", "Member"))
.Destroy(update => update.Action("Grid_Member_Destroy", "Member"))
)
)
我在控制器中设置了,但当我运行时,IE告诉我:
Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
Source Error:
Line 3: @(Html.Kendo().Grid<RegistrationManagement.Models.Member>()
Line 4: .Name(Html.ViewBag.PrettyID)
Line 5: .Columns(columns =>
Line 6: {
Line 7: columns.Bound(p => p.LastName);
编译器错误消息:CS1977:如果不首先将lambda表达式强制转换为委托或表达式树类型,则无法将其用作动态调度操作的参数
源错误:
第3行:@(Html.Kendo().Grid())
第4行:。名称(Html.ViewBag.PrettyID)
第5行:。列(列=>
第6行:{
第7行:columns.Bound(p=>p.LastName);
我认为这是由于Html.ViewBag.PrettyID没有被解析。如何为每个剑道网格创建一个唯一的名称
谢谢!您应该尝试将其转换为字符串:
.Name((String)Html.ViewBag.PrettyID)
如果不关心实际值,可以使用Guid.NewGuid()
:
成功了。谢谢!网格现在有唯一的名称并显示相应的结果集。
.Name((String)Html.ViewBag.PrettyID)
.Name("grid" + Guid.NewGuid().ToString())