这是主网格,我正在尝试使用弹出网格选择更新主网格字段。请帮助我。这段代码将通过选择弹出窗口更新主网格。但没有设定模型。所以我在控制器上获得了价值。我该如何解决这个问题?
<a id="window"></a>
@(Html.Kendo().Grid<IBATechnologies.IBA.Web.Models.AssetLocationViewModel>()
.Name("GridLocation")
.Columns(columns =>
{
//columns.Bound(p => p.UserId).Width(125);
columns.Bound(p => p.CampanyCode).Width(125);
columns.Bound(p => p.location1code).Width(165).Filterable(false);
columns.Bound(p => p.location2code).Width(150).Filterable(false);
columns.Bound(p => p.locationCode).Width(125);
columns.Bound(p => p.Name).Width(150);
columns.Bound(p => p.ShortName).Width(150);
columns.Bound(p => p.CreatedBy).Width(150);
columns.Bound(p => p.ModifyBy).Width(150);
//columns.Bound(p => p.Designation).Width(150);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
})
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Sortable()
.Scrollable()
.Selectable()
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
)))
.HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
//.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.locationCode))
.Create(update => update.Action("AssetLocEditingPopup_Create", "Location"))
.Read(read => read.Action("AssetLocationEditingPopup_Read", "Location"))
.Update(update => update.Action("AssetLocEditingPopup_Update", "Location"))
.Destroy(update => update.Action("AssetLocEditingPopup_Destroy", "Location"))
)
)
<script type="text/javascript">
$(document).ready(function () {
$("#GridLocation").on("dblclick", " tbody > tr > td", function () {
//model.location2code = 100;
//var grid = $("#GridLocation").data("kendoGrid");
//var data = grid.datasource.at(0);
////data.set("location1code", l1locode);
//alert(data.location1code);
//var gridDataArray = $('#GridLocation').data('kendoGrid')._data;
//var columnDataVector = [];
//var columnName = 'location1code';
////for (var index = 0; index < gridDataArray.length; index++) {
//// columnDataVector[index] = gridDataArray[index][columnName];
////};
////alert(columnDataVector[0]);
//gridDataArray[0].text("location1code", "frfrf");
//$("#locapopupWindow").data('kendoWindow').open();
$("#window").load("@Url.Action("PopupWindow", "Location")");
//$(this).load("/Shared/_assetLocationPopup");
$('#GridLocation').data('kendoGrid').refresh()
//firstItem.dirty = true; // set it as dirty
//$('#GridLocation').data().kendoGrid.dataSource.sync();
});
});
这是带网格的弹出窗口
@{Html.Kendo().Window()
.Name("locapopupWindow")
.Title("Select Location")
.Draggable()
.Width(500)
.Height(300)
.Actions(actions => actions
.Custom("custom")
.Minimize()
.Maximize()
.Close()
)
.Content(@<text>
@{Html.Kendo().Grid<IBATechnologies.IBA.Web.Models.AssetLocationViewModel>()
.Name("locationpopupGrid")
.Columns(columns =>
{
columns.Bound(p => p.CampanyCode).Width(125).Visible(false);
columns.Bound(p => p.location1code).Width(165).Visible(false);
columns.Bound(p => p.location2code).Width(150).Visible(false);
columns.Bound(p => p.Name).Width(150);
columns.Bound(p => p.ShortName).Width(150);
columns.Bound(p => p.CreatedBy).Width(150).Visible(false);
columns.Bound(p => p.ModifyBy).Width(150).Visible(false);
})
.Pageable()
.Sortable()
.Scrollable()
.Selectable()
.Filterable(filterable => filterable
.Extra(false)
.Operators(operators => operators
.ForString(str => str.Clear()
.StartsWith("Starts with")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
)))
.HtmlAttributes(new { style = "height:250px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
//.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.location1code))
.Create(update => update.Action("Level2LocEditingPopup_Create", "Asset"))
.Read(read => read.Action("Level2LocationEditingPopup_Read", "Location"))
)
.Render();
}
)
.Render();
}
$(document).ready(function (){
$("#locationpopupGrid").data("kendoGrid").bind("change", enter code hereonLocationRowSelected);
$("#locapopupWindow").data("kendoWindow").bind("close", onWindowClose);
function onLocationRowSelected()
{
var grid = $("#locationpopupGrid").data("kendoGrid");
var selectedItem = grid.dataItem(grid.select());
orisfunction(selectedItem.location1code, enter code hereselectedItem.location2code);
$("#locapopupWindow").data("kendoWindow").close();
$("#locapopupWindow").data("kendoWindow").destroy();
}
function orisfunction(l1locode, l2locode)
{
var grid = $("#GridLocation").data("kendoGrid");
var data = grid.dataSource.data()[0];
// Here I am trying to update grid, here data is shows in grid cell but not update model so i cant get value at controlller
data.set("location1code", l1locode);
data.set("location2code", l2locode);
}
function onWindowClose()
{
$("#locapopupWindow").data("kendoWindow").destroy();
}
});
请帮帮我