Note: It seems your forum no longer has formatting options for pasting code.
I have an odd behavior where I can't pass a String value from my model to the JavaScript behind the Grid. I pass int? values without issue but Strings do not pass.
This works fine:
var customerId = Number(@Model.CustomerId);
This does not work:
var uniqueId = @Model.CustomerUniqueId;
var uniqueId = String(@Model.CustomerUniqueId);
My full grid and scripts:
@(Html.Kendo().Grid<Person>()
.Name("grid")
.Columns(columns =>
{
columns.Command(command => command
.Custom("Detail")
.Click("goDetail"))
.Width(Glossary.Portal.ButtonWidth);
columns.Bound(p => p.FirstName)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")
.ShowOperators(false)
.SuggestionOperator(FilterType.Contains)));
columns.Bound(p => p.LastName)
.Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")
.ShowOperators(false)
.SuggestionOperator(FilterType.Contains)));
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("IndexJson", "Persons")
.Data("getData"))
))
<script type="text/javascript">
var customerId = Number(@Model.CustomerId);
var customerInfoId = Number(@Model.CustomerInfoId);
var groupId = Number(@Model.GroupId);
var sessionId = Number(@Model.SessionId);
function getData() {
return {
customerId: customerId,
customerInfoId: customerInfoId,
groupId: groupId,
sessionId: sessionId
};
}
function goDetail(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
window.location.href = '@Url.Action("Details", "Persons")?id=' + dataItem.Id + '&customerId=' + customerId + '&customerInfoId=' + customerInfoId + '&groupId=' + groupId + '&sessionId=' + sessionId;
}
function error_handler(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors,
function(key, value) {
if ('errors' in value) {
$.each(value.errors,
function() {
message += this + "\n";
});
}
});
alert(message);
}
}
</script>