我正在开发一个视频应用程序,我想使用视频播放器 API (Flowplayer) 跟踪用户的操作。 我通过在每个事件上设置一个事件监听器来处理“播放、暂停、恢复等”来做到这一点。使用 JavaScript 的事件。捕获事件后,我调用放置在服务器端的静态方法,以便将操作写入数据库(并向用户隐藏跟踪信息)。
这就是我现在得到的:
JS 代码:
<script type="text/javascript">
// bind listeners to all players on the page
flowplayer(function (api, root) {
api.bind("pause", function () {
console.info("pause", api.paused);
var timePassed = api.video.time;
@{
Reporter.ReportPause(timePassed);
}
//... more code ...
</script>
C# 代码:
public static void ReportPause ( string timePassed)
{
// do something with timePassed
}
我遇到异常:“无法解析符号‘timePassed’”。
我怎样才能以正确/优雅的方式做到这一点(以最小的开销)。
谢谢大家, 青年网
最佳答案
<script type="text/javascript">
// bind listeners to all players on the page
flowplayer(function (api, root) {
api.bind("pause", function () {
console.info("pause", api.paused);
var timePassed = $.flowplayer().getTime();
$.ajax({
url: '/Home/ReportPause',
type: 'POST',
dataType: "json",
data: { timePassed: timePassed },
error: function (a, b, c) { onError(a, b, c, parameters); },
success: function (data) { onSuccess(data, parameters); }
});
});
}
</script>
// Controller
public class HomeController{
public JsonResult ReportPause(string timePassed)
{
TimePassedClass.ReportPause(timePassed);
// more code
}
}
public static class TimePassedClass
{
public static void ReportPause(string timePassed)
{
// your logic
}
}
关于javascript - ASP MVC 4,将数据从 javascript (View) 传递到 C# 静态方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18589788/