【发布时间】:2018-11-14 16:08:36
【问题描述】:
在我的 DotNet Core 应用程序中,我设置了一个按钮,其中包含一些 JavaScript,用于我的 OnClick 事件。它看起来像这样:
<div>
@(Html.DevExtreme().Button()
.Text("Press me")
.Type(ButtonType.Normal)
.Width(90)
.OnClick("notify")
)
</div>
<script>
function notify() {
console.log("pressed");
// ModifiedDuration.AdjustmentScreen_Netting.Csharp.RunBatch();
// var a = '<%=RunBatch()%>';
}
</script>
注释掉的行是我尝试调用的目标方法,但都没有工作。我要调用的底层方法是这样的:
public void RunBatch()
{
Console.WriteLine("Re-running batch");
TestOutput print= new TestOutput ();
print.TestMethod();
}
那么,TestMethod 做了什么:
public void ProcessAdjustedBatch()
{
Console.WriteLine("I have been called from the datagrid!!!!");
}
所以在我按下按钮后,我希望看到以下日志消息:
- 按下
- 重新运行批处理
- 我已从数据网格中调用!!!!
但我在开发日志中看到的只是Pressed。我怎样才能达到我的预期输出?
【问题讨论】:
-
function notify()在客户端进行评估,但我认为public void RunBatch()是您后端的一部分。因此浏览器不能使用函数RunBatch。您可以为此方法公开一个 HTTP 接口并通过 HTTP 调用它 -
这是两个不同的部分。第一个是写入浏览器日志,第二个是写入控制台。您正在混淆客户端和服务器。
标签: javascript c# asp.net-mvc .net-core devextreme