1

我有一个简单的问题:使用剑道窗口,我可以像这样刷新它:

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})',

但以上不起作用,变量无法识别。我怎样才能做到这一点?

4

1 回答 1

2

如果您的变量将是一个字符串,那么您始终可以使用 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 +'})',
于 2015-01-29T11:13:08.690 回答