I have grid on the button click , which takes parameters from viewbag. It works fine when first time loads. when i click the button for the different record, it still takes the same parameter values of the first one.
<
div
class
=
"container-fluid"
>
<
div
class
=
"row"
>
<
div
class
=
"col-xs-18 col-md-12"
>
@(Html.Kendo().Grid<
BHEBS.Areas.Budget.Models.ContractBudgetModel.contractBudgetServiceBUModel
>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.Id).Hidden(true);
columns.Bound(p => p.CB_Id).Hidden(true);
columns.Bound(p => p.Contractor_Id).Hidden(true);
columns.Bound(p => p.Sd_Id).Hidden(true);
columns.Bound(p => p.BUId);
columns.Bound(p => p.BudgetDetailAmt).EditorTemplateName("Currency").Format("{0:c}");
columns.ForeignKey(p => p.ProviderSpendPriority, (System.Collections.IEnumerable)ViewData["SpendPriority"], "Id", "SpendPriority");
columns.Bound(p => p.ContractBudgetAmount).Format("{0:c}");
columns.Bound(p => p.ContractSpendPriority);
columns.Bound(p => p.MasterBudgetAmount).Format("{0:c}");
columns.Command(command =>
{
command.Edit().HtmlAttributes(new { @class = "btn-primary" });
command.Destroy().HtmlAttributes(new { @class = "btn-primary" });
}).Width(300);
// columns.Command(command => command.Custom("Remove").SendDataKeys(true).Click("deleteClick").HtmlAttributes(new { @class = "k-button k-button-icontext k-grid-add k-primary" }));
})
//.Events(e => e.DataBound("onDataBound"))
.Pageable(pageable => pageable.Refresh(true).PageSizes(true).ButtonCount(5))
.Sortable()
.Scrollable()
.Filterable()
.Selectable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height:450px;" })
.DataSource(dataSource => dataSource.Ajax().PageSize(10).Read(read => read.Action("ContractBudgetServiceBU_Read", "ContractBudget", new { contractorId = ViewBag.contractorId, contractId = @Html.Raw(Json.Encode(Model.Id)), serviceDetailId = ViewBag.serviceDetailId }))
.Model(model =>
{
model.Id(p => p.Id); model.Field(p => p.Id).Editable(false); model.Field(p => p.CB_Id).Editable(false); model.Field(p => p.Contractor_Id).Editable(false);
model.Field(p => p.Sd_Id).Editable(false); model.Field(p => p.ContractBudgetAmount).Editable(false); model.Field(p => p.ContractSpendPriority).Editable(false); model.Field(p => p.MasterBudgetAmount).Editable(false);
})
.Update(update => update.Action("Update_ContractBudgetServiceBU", "ContractBudget")).Destroy(destroy => destroy.Action("Destroy_ContractBudgetServiceBU", "ContractBudget"))
.Events(e => e.Error(@<
text
>
function(args) {
var gridName = 'grid';
errorGrid(args, gridName); } </
text
>)) ))
</
div
>
</
div
>
</
div
>
@(Html.Kendo().Window()
.Name("window")
.Title("Assign Business Units")
.Content(@<
text
><
div
class
=
"container-fluid"
>
<
div
class
=
"row"
>
<
div
class
=
"col-xs-18 col-md-12"
>
@(Html.Kendo().Grid<
BHEBS.Areas.Budget.Models.ContractBudgetModel.contractBudgetBUModel
>()
.Name("grid1")
.Columns(columns =>
{
columns.Template(x => { }).HtmlAttributes(new { @class = "chkbox" }).ClientTemplate("<
input
type
=
'checkbox'
class
=
'checkbox'
id
=
'chk'
/>");
columns.Bound(p => p.Id);
columns.Bound(p => p.BusinessUnit);
columns.Bound(p => p.Description);
columns.Bound(p => p.ServiceType);
columns.Bound(p => p.ContractBUAmt).Format("{0:c}");
})
.Pageable(pageable => pageable.Refresh(true).PageSizes(true).ButtonCount(5))
.Sortable()
.Scrollable()
.Filterable()
.Selectable()
.Resizable(resize => resize.Columns(true))
.HtmlAttributes(new { style = "height:450px;" })
// this is the grid am talking about. These take parameters.
.DataSource(dataSource => dataSource.Ajax().PageSize(10).Read(read => read.Action("GetAllContractBudget_Read", "ContractBudget", new { contractId = @Html.Raw(Json.Encode(Model.Id)), contractorId = @ViewBag.ContractorId, serviceDetailId = @ViewBag.ContractDetailBudgetService.ServiceDetailId })).Model(model => model.Id(p => p.Id))))
<
button
class
=
"k-button close-button k-primary"
style
=
"bottom: 10px; "
>Cancel</
button
>
<
button
class
=
"k-button k-primary"
id
=
"showSelection"
style
=
"bottom: 10px; "
>Assign</
button
>
</
div
>
</
div
>
</
div
></
text
>)
.Draggable()
.Resizable()
.Width(1000)
.Modal(true)
.Visible(false))
$(document).ready(function(){
var serviceId = '@(ViewBag.serviceDetailId)';
alert(serviceId);
$("#kendowindow").click(function(){
$("#window").data("kendoWindow").center().open();
$("#grid1").css("margin-right","30px");
// this is how am refreshing the grid. This works fine for the first time for the first record. when i go back to another page and come back with some other parameter values, i can see the viewbag values or proper, but when i click the button read method has first time parameters.
$('#grid1').data().kendoGrid.dataSource.read();
});
});