chiapa
chiapa

Reputation: 4412

Passing parameter to Controller Action from Kendo Window refresh in javascript

I have got a simple question: with a Kendo window, I can refresh it like this:

window.refresh({
    url: '@Url.Action("_EditScheduleInspectionForm", "TLM")',

I want to pass a parameter to that Controller Action. I tried the following and it works:

window.refresh({
    url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "test"})',

Controller

public PartialViewResult _EditScheduleInspectionForm(string test)

The test variable comes filled with the passed string "test". But I don't want to hardcode the string, I want to pass a javascript variable there, like:

var test = "something";
window.refresh({
    url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = test})',

But the above doesn't work, the variable isn't recognized. How can I achieve this?

Upvotes: 1

Views: 2917

Answers (1)

Nitin Mall
Nitin Mall

Reputation: 462

If your variable is going to be a string then you can always use replace to replace the static value with the variable value. Please see below:

var url = '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "testvalue"})',,

var jsvariable = "something";

window.refresh({
url: url.replace("TLM",jsvariable ),

Or in a simpler way you can directly do it as below:

var test = "something";
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = ' + test +'})',

Upvotes: 2

Related Questions