将参数从 Kendo Window 刷新到 javascript 中的控制器操作
Passing parameter to Controller Action from Kendo Window refresh in javascript
我有一个简单的问题:有了 Kendo window,我可以这样刷新它:
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM")',
我想将参数传递给该控制器操作。我尝试了以下方法并且有效:
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "test"})',
控制器
public PartialViewResult _EditScheduleInspectionForm(string test)
test
变量填充了传递的字符串 "test"。但是我不想对字符串进行硬编码,我想在那里传递一个 javascript 变量,例如:
var test = "something";
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = test})',
但上面的方法不起作用,无法识别变量。我怎样才能做到这一点?
如果您的变量将是一个字符串,那么您始终可以使用 replace 将静态值替换为变量值。请看下面:
var url = '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "testvalue"})',,
var jsvariable = "something";
window.refresh({
url: url.replace("TLM",jsvariable ),
或者更简单的方法,你可以直接如下:
var test = "something";
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = ' + test +'})',
我有一个简单的问题:有了 Kendo window,我可以这样刷新它:
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM")',
我想将参数传递给该控制器操作。我尝试了以下方法并且有效:
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "test"})',
控制器
public PartialViewResult _EditScheduleInspectionForm(string test)
test
变量填充了传递的字符串 "test"。但是我不想对字符串进行硬编码,我想在那里传递一个 javascript 变量,例如:
var test = "something";
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = test})',
但上面的方法不起作用,无法识别变量。我怎样才能做到这一点?
如果您的变量将是一个字符串,那么您始终可以使用 replace 将静态值替换为变量值。请看下面:
var url = '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = "testvalue"})',,
var jsvariable = "something";
window.refresh({
url: url.replace("TLM",jsvariable ),
或者更简单的方法,你可以直接如下:
var test = "something";
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM", new { test = ' + test +'})',