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

Grid custom command does not find javascript function

1 Answer 451 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Derek
Top achievements
Rank 1
Derek asked on 25 Jun 2019, 02:13 PM

Hi

I have based the following code on Grid / Custom command
https://demos.telerik.com/aspnet-mvc/grid/custom-command


@(Html.Kendo().Grid<MyProject.Models.Profiles>().
    Name("MyTable").
    Columns(columns =>
    {
        columns.Command(command => {
            command.Custom("Edit Details").Click("EditDetails");
        }).Width(120);
    })
    .HtmlAttributes(new { style = "height: 600px" })
    .BindTo(Model)
    .Scrollable()
    .Groupable()
    .Sortable()
    .Filterable()
)
 
<script>
    function EditDetails(e) {
        e.preventDefault();
    }
</script>

When I run the code I get the following error in the Developer Console(Edge & Chrome)
Uncaught ReferenceError: EditDetails is not defined

I have been unable to find the problem, any suggestions?

Is there a way that i can call a controller method without going through javascript?

 

Thanks

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Jun 2019, 06:26 AM
Hi Derek,

Try moving the function declaration above the grid.

On redirecting to an action - I an think of two easy ways:

  • use JS and call window.location.href = "mycontorller/myaction/someparam" where the event arguments of the custom command handler can be used to get the current row data item and use its fields in constructing the url
  • use the ClientTemplate of a column and place an anchor there that will point to the desired url - in a similar fashion, build its parameters with the data that comes from the model

 


Regards,
Marin Bratanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Derek
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or