To pass a parameter to the Kendo Dialog action method, ensure the parameter is correctly formatted as a string in JavaScript. Based on your code, you need to wrap parameter in quotes:
@{
var action_name = "delete";
}
@(Html.Kendo().Dialog()
.Name("dialog")
.Title("Software Update")
.Actions(actions =>
{
actions.Add().Text("OK");
actions.Add().Text("Cancel").Action("onCancel('" + action_name + "')"); // Wrap parameter in quotes
})
)
<script type="text/javascript">
function onCancel(action_name) {
alert(action_name); // Will display 'delete'
}
</script>
Using the above code, the onCancel method will trigger when the page loads, instead of clicking the Cancel button. To make the onCancel method works with the Cancel button, we could modify the code as below:
@{
var action_name = "delete";
}
@(Html.Kendo().Dialog()
.Name("dialog")
.Title("Software Update")
.Actions(actions =>
{
actions.Add().Text("OK");
actions.Add().Text("Cancel").Action("function() { onCancel('"+ action_name +"') }"); // Wrap parameter in quotes
})
)
<script type="text/javascript">
function onCancel(action_name) {
alert(action_name); // Will display 'delete'
}
</script>