Good day,
I have a question since all solutions I've found so far didn't work in my case. Hre's a brief description of what I have... So, I have my kendoGrid with all the info displayed. I'm trying to make a button for certain rows which will call a method in my Controller. Here's the code on my page:
@(Html.Kendo().Grid<DisplayEntitiesViewModel>()
.Name(
"CustomersGrid"
)
.Columns(columns =>
{
columns.Bound(c => c.CustomerId).Hidden(
true
);
columns.Bound(c => c.CustomerName)
.Width(150);
columns.Bound(c => c.CustEmail)
.Width(800);
columns.Command(command => command
.Custom(
"Add Contact"
)
.Visible(
"showButton"
)
.Click(
"AddContact"
)).Width(180);
})
.HtmlAttributes(
new
{style =
"height: 580px; width: 1133px; margin-left: 16px"
})
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(
true
)
.PageSizes(
true
)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action(
"ReadCustomers"
,
"MyController"
))
.PageSize(20)
)
)
Here's my script with the AJAX call:
function
AddContact(c) {
var
row = $(c.target).closest(
"tr"
);
var
grid = $(
'#acombaGrid'
).data(
'kendoGrid'
);
var
dataItem = grid.dataItem(row);
$.ajax({
url:
'@Url.Action("DispalyEntities", "MyController")'
,
dataType:
"json"
,
contentType:
"application/json"
,
data: {
customerId: dataItem.CustomerId
},
cache:
false
,
type:
"POST"
});
}
Here's in brief my Controller:
public
IActionResult DispalyEntities(
string
customerId)
{
return
View();
}
My problem is, no matter what I've done so far... my costomerId passed to the controller is always null. Could you please point me what's wrong with it. Thanks in advance for doing so.