脚本不起作用(ASP.NET MVC)

时间:2017-03-31 10:38:45

标签: asp.net ajax asp.net-mvc

我有录制视频的脚本

这是代码

var fileName;
stop.onclick = function () {
    record.disabled = false;
    stop.disabled = true;
    window.onbeforeunload = null; //Solve trouble with deleting video
    preview.src = '';

    fileName = Math.round(Math.random() * 99999999) + 99999999;
    console.log(fileName);
    var full_url = document.URL; // Get current url
    var url_array = full_url.split('/') // Split the string into an array with / as separator
    var id = url_array[url_array.length - 1];  // Get the last part of the array (-1)
     function save() {
        $.ajax({
            type: 'Post',
            dataType: 'Json',
            data: {
                link: fileName,
                id: id,
            },
            url: '@Url.Action("LinkWriter", "Interwier")',
            success: function (da) {
                if (da.Result === "Success") {

                    alert("lol");

                } else {

                    alert('Error' + da.Message);
                }
            },
            error: function (da) {
                alert('Error');
            }
        });
    }

我尝试使用此行var id = url_array[url_array.length - 1]; // Get the last part of the array (-1)

获取网址

并使用此代码写入表文件名

 $.ajax({
            type: 'Post',
            dataType: 'Json',
            data: {
                link: fileName,
                id: id,
            },
            url: '@Url.Action("LinkWriter", "Interwier")',
            success: function (da) {
                if (da.Result === "Success") {

                    alert("lol");

                } else {

                    alert('Error' + da.Message);
                }
            },
            error: function (da) {
                alert('Error');
            }
        });
    }

但它不起作用。

有我的Action方法

 [HttpPost]
    public ActionResult LinkWriter(string link, int id) {

        Link link_ = new Link
        {
            Link1 = link,
            Interwier_Id = id,

        };

        db.Link.Add(link_);
        db.SaveChanges();
        return View();
    }      

但它不起作用。我的错误在哪里?

更新

据我所知,这不起作用

function save() {
    $.ajax({
        type: 'Post',
        dataType: 'Json',
        data: {
            link: fileName,
            id: id,
        },
        url: '@Url.Action("LinkWriter", "Interwier")',
        success: function (da) {
            if (da.Result === "Success") {

                alert("lol");

            } else {

                alert('Error' + da.Message);
            }
        },
        error: function (da) {
            alert('Error');
        }
    });
}

0 个答案:

没有答案