如何在ASP.NET MVC中从Javascript调用vb脚本函数

时间:2015-05-14 09:39:18

标签: javascript asp.net-mvc-4 razor vbscript

我正在从Javascript调用vbscript函数“MyVbalert”,但是vbscript事件没有触发。我想要点击“选择”按钮时它应该激活一个vbscript功能。即使在IE中它也无法在任何浏览器中工作

 <script type="text/vbscript">
        Function MyVbalert()
        {
            MsgBox("Hello from VB Script !")
           End Function
        }


    </script>


<script>
            $(document).ready(function () {
                $("#files").kendoUpload({
                    async: {
                        saveUrl: "abc/xyz",
                        //  removeUrl: "remove",
                        autoUpload: true
                    },
                    complete: onComplete,
                    error: onError,
                    select: onSelect,
                    success: onSuccess,
                    upload: onUpload
                });
            });

            function onSelect(e) {
                MyVbalert()

            }

            function onUpload(e) {
                //  console.log("Upload :: " + getFileInfo(e));
            }

            function onSuccess(e) {
                // console.log("Success (" + e.operation + ") :: " + getFileInfo(e));

                console.log(e.response);
                $("#excelfilepath").val(e.response.filename);
                $("#excelPreview").kendoGrid({
                    dataSource: e.response.list,
                    columns: [
                         {
                             field: "Question",
                             title: "Question"
                         },
                         {
                             field: "Option1",
                             title: "Option1"
                         },
                           {
                               field: "Option2",
                               title: "Option2"
                           },
                            {
                                field: "Option3",
                                title: "Option3"
                            },
                             {
                                 field: "Option4",
                                 title: "Option4"
                             }
                             ,
                             {
                                 field: "Solution",
                                 title: "Solution"
                             },
                             {
                                 field: "Answer",
                                 title: "Answer"
                             }
                    ],
                    scrollable: true,
                    pageable: true,
                    pageSize: 20
                });
                //$.each(e.response, function (i,val) {
                //    console.log(val);
                //});
            }

            function onError(e) {
                //  console.log("Error (" + e.operation + ") :: " + getFileInfo(e));
            }

            function onComplete(e) {
                // console.log("Complete");
            }
            function getFileInfo(e) {
                return $.map(e.files, function (file) {
                    var info = file.name;

                    // File size is not available in all browsers
                    if (file.size > 0) {
                        info += " (" + Math.ceil(file.size / 1024) + " KB)";
                    }
                    return info;
                }).join(", ");
            }
            </script>

1 个答案:

答案 0 :(得分:0)

 <script type="text/vbscript">

声称以下代码是VBScript。但

Function MyVbalert()
{
   MsgBox("Hello from VB Script !")
   End Function
}

是J(ava)脚本和VBScript的混合。用干净的VBScript Sub替换它:

Sub MyVbalert()
  MsgBox "Hello from VBScript!"
End Sub

并将其称为

MyVbalert

(标记假的虚假() - VBScript不是Lisp)