【问题标题】:C # MVC how to call the url from jqueryC#MVC如何从jquery调用url
【发布时间】:2020-05-13 16:37:11
【问题描述】:

我下面有一个锚类

<a class="delete" href="@Url.Action("methodname","controller", new { id= "18"})">delete</a>

下面还有一个 Div 类

<div id="confirmation" hidden = "hidden">  <p>Are you sure you want to delete this item?</p>  </div>

下面是jquery

//一旦用户点击删除,下面将打开div确认框

$(document).ready(function () {

    $(".delete").click(function () {

        $('#confirmation').dialog('open');
        return false;
    });
});

// 我有两个按钮继续和取消,一旦用户单击继续,我需要使用参数调用该 URl 操作

$(document).ready(function () {
   $('#confirmation').dialog({

        autoOpen: false 
        buttons: {
            "Continue": function () {

                //code here
                $(this).dialog("close");
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });
});                  

【问题讨论】:

    标签: jquery model-view-controller


    【解决方案1】:

    你可以这样做

     $.ajax({
        type: "POST",
        data: {
                id: id,
            },
        url: "/Controller/Method",
        dataType: "json",
        success: function (result) {
            window.location.href = "/Controller/Method";
        },
        error: function (result) {
            alert(result.responseText);
        },
    });
    

    【讨论】:

    • 感谢您的回复,如何将id值从一个类传递到另一个类
    • 如果你的方法有一个 id 参数,你的方法应该得到 id 的值
    猜你喜欢
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多