我有一个简单的问题:使用Kendo窗口,我可以像这样刷新它:
window.refresh({
url: '@Url.Action("_EditScheduleInspectionForm", "TLM")',
我想将参数传递给Controller Action。我尝试了以下内容并且有效:
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})',
但是上述方法无效,变量无法识别。我怎样才能做到这一点?
答案 0 :(得分: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 +'})',