我已经创建了一个电子学习系统,现在我正在尝试使用 Rustici 创建的 Javascript 库集成 tincanapi,我想知道是否可以从 MVC 控制器调用 javascript 方法。在 web 视图中,我使用以下代码创建 tincan 语句:
<script type="text/javascript" src= "@Url.Content("~/Scripts/tincan.js")"></script>
var tincan = new TinCan
(
{
recordStores: [
{
endpoint: "https://cloud.scorm.com/tc/V4FF9VBCSY/",
username: "myusername",
password: "mypassword"
}
]
}
);
function AcceptFriend(fullName,emailAddress)
{
tincan.sendStatement
(
{
actor: {
name: "@Model.User.Forename" + " @Model.User.Surname",
mbox: "@Model.User.Email"
},
verb: {
id: "http://adlnet.gov/expapi/verbs/answered",
display: {
"en-US": "accepted a friend request from"
}
},
target: {
objectType: "Agent",
name: fullName,
mbox: emailAddress
}
}
);
};
此代码在单击接受好友请求按钮时调用,该按钮运行良好且非常好。
但是现在我想跟踪用户何时上传课程,当然我可以在提交表单时执行此操作,但这让我不确定上传是否成功,所以我认为最好在如果可能,控制器动作。这可以做到吗?我如何在此代码中调用与上述类似的语句:
public ActionResult NewCampaign()
{
evm.GetCampaignTypes();
evm.GetCampaignFormats();
evm.GetCampaignTemplates();
//Set ViewBag values.
ViewBag.UserID = evm.User.UserID;
ViewBag.NewMessageCount = evm.NewMessageCount;
ViewBag.PendingFriendRequests = evm.PendingFriendRequests;
ViewBag.NewFriendRequest = evm.NewFriendRequest;
ViewBag.NewFriendCount = evm.NewFriendCount;
ViewBag.UserForename = evm.User.Forename;
return View(evm);
}