This is a migrated thread and some comments may be shown as answers.

Grid JavaScript Strings

5 Answers 91 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Joel asked on 13 Feb 2020, 09:48 PM

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>

 

5 Answers, 1 is accepted

Sort by
0
Joel
Top achievements
Rank 2
Iron
Iron
Iron
answered on 14 Feb 2020, 04:55 PM

I hate JavaScript.  This works:

var customerUniqueId = '@Model.CustomerUniqueId';

Put quotes around it.

0
Joel
Top achievements
Rank 2
Iron
Iron
Iron
answered on 14 Feb 2020, 04:56 PM
Where is the button that marks this answered?  Your forum has taken a step backward.
0
Accepted
Silviya Stoyanova
Telerik team
answered on 17 Feb 2020, 11:36 AM

Hello, Joel, 

I am glad to read you found a way to solve the original question.

Thank you for pointing out that the forum's formatting options are missing. This has already been reported to us by another client and we addressed it to the attention of the responsible team.

Also, you could find the button "Mark as answered" under the Reply button if you are logged in.

 

Regards, Silviya Stoyanova Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
0
Joel
Top achievements
Rank 2
Iron
Iron
Iron
answered on 19 Feb 2020, 02:58 PM
Yes, but I can't mark my own post as the answer... only your post has that link.
0
Silviya Stoyanova
Telerik team
answered on 24 Feb 2020, 09:10 AM

Hi, Joel,

Thank you for helping us to improve.

We have sent a request to the responsible team.

For your contribution, I have added some Telerik points to your account.

Regards, Silviya Stoyanova Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Grid
Asked by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Joel
Top achievements
Rank 2
Iron
Iron
Iron
Silviya Stoyanova
Telerik team
Share this question
or