Jquery 通过单击链接将数据发送到模式窗口

Jquery 通过单击链接将数据发送到模式窗口,jquery,asp.net-mvc-3,Jquery,Asp.net Mvc 3,我有下面的代码,可以对工作正常的控制器进行ajax调用 @Ajax.ActionLink("Add to Wishlist", "Add", "Wishlist", new { productId = Product.ProductId }, new AjaxOptions { UpdateTargetId = "breadcrumbs", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" }, new { @class = "

我有下面的代码,可以对工作正常的控制器进行ajax调用

@Ajax.ActionLink("Add to Wishlist", "Add", "Wishlist", new { productId = Product.ProductId }, new AjaxOptions { UpdateTargetId = "breadcrumbs", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" }, new { @class = "button" })
现在我需要更改此代码,并允许用户在添加产品Id的同时添加一些额外的数据

现在的要求是,当点击“添加到愿望列表”链接时,打开一个模式弹出窗口,在模式窗口中显示一个下拉列表和一个文本框,用户填写后,点击模式弹出窗口中的提交按钮,然后将数据发送给控制器

现在,我的页面有多个这样的链接,所有链接都有不同的productId

我的第一个问题是如何将产品Id发送到模式弹出窗口

谢谢 Arnab在主视图中(从中启动模态的视图):


希望这有帮助。

使用
Html.ActionLink
helper方法切换到正常链接

@Html.ActionLink("Add to Wishlist", "Add", "Wishlist",
                           new { @id=product.ProductId},new { class="modelLink"})
现在执行一些javascript来侦听此链接的单击事件,然后打开对话框并发送所需的任何参数。下面的代码正在打开一个模型弹出窗口((这意味着,您需要包含jQuery UI库,此代码才能工作)),并且它正在向
WishList
控制器的
Add
操作方法发送2个参数。无论您从addaction方法返回什么,都将显示在Model对话框中

$(function(){    
  $('a.modelLink').click(function(){

     var item=$(this);

     var url=item.attr("href")+"&anotherParam=unicorn";

        var dialog = $("#dialog");
        if ($("#dialog").length == 0) {
            dialog = $('<div id="dialog" style="display:hidden"></div>').appendTo('body');
        }
        dialog.load(
            url,
            {}, // omit this param object to issue a GET request instead a POST request, otherwise you may provide post parameters within the object
            function (responseText, textStatus, XMLHttpRequest) {
                dialog.dialog({                       
                    close: function (event, ui) {                            
                        dialog.remove();
                    },
                    modal: true,
                    width: 460
                });
            }
        );
    }); 

});
$(函数(){
$('a.modelLink')。单击(函数(){
var项目=$(此项);
var url=item.attr(“href”)+“&anotherParam=unicorn”;
变量对话框=$(“#对话框”);
如果($(“#对话框”).length==0{
dialog=$('').appendTo('body');
}
dialog.load(
网址,
{},//省略此param对象以发出GET请求,而不是POST请求,否则您可能会在对象内提供POST参数
函数(responseText、textStatus、XMLHttpRequest){
dialog.dialog({
关闭:函数(事件,ui){
dialog.remove();
},
莫代尔:是的,
宽度:460
});
}
);
}); 
});

但是如何在客户端通过链接click添加tempdata在模式弹出窗口中,我可能会有一个textboxfor和dropdownlistfor以及一个submit按钮,如何在submit click上调用“var prodId”我写的内容在客户端。您不是在单击时执行此操作,而是在单击之前执行此操作,一旦知道Id,就将其存储在TempData中。一旦您需要它在您的模态-您检索它如上所示。如果你有任何困难,请告诉我。
@Html.ActionLink("Add to Wishlist", "Add", "Wishlist",
                           new { @id=product.ProductId},new { class="modelLink"})
$(function(){    
  $('a.modelLink').click(function(){

     var item=$(this);

     var url=item.attr("href")+"&anotherParam=unicorn";

        var dialog = $("#dialog");
        if ($("#dialog").length == 0) {
            dialog = $('<div id="dialog" style="display:hidden"></div>').appendTo('body');
        }
        dialog.load(
            url,
            {}, // omit this param object to issue a GET request instead a POST request, otherwise you may provide post parameters within the object
            function (responseText, textStatus, XMLHttpRequest) {
                dialog.dialog({                       
                    close: function (event, ui) {                            
                        dialog.remove();
                    },
                    modal: true,
                    width: 460
                });
            }
        );
    }); 

});