如何在jQUERY中传递ID [英] How To pass Id in jQUERY

查看:544
本文介绍了如何在jQUERY中传递ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想在弹出窗口中执行编辑,我有代码,但无法正常工作

Want to perform Edit in popup, I have code but its not working

这是我的剧本

  $("#mylink").click(function(e) {
    var count = 0; 
    var $dialog = $("<div id='divCreateTask'></div>");
    var Id = $(this).data(e);//       
    url: "TaskTimeSheet/EditTaskPopUp/" + Id //       
    var url = "EditTaskUrl" + id;var url = '@Url.Action("EditTaskPopUp", "TaskTimeSheet")'; 
    url += '/?Id=' +Id; $("#tab1").load(url);
    $dialog.empty();$dialog.dialog({  
                         autoOpen: true, 
                         width: 600,
                         height: 650,
                         resizable: false,
                         modal: true,
                         open: function (event, ui) { 
                              $(this).load(url);   
                              },
                        buttons: { 
                              "Cancel": function () { 
                                    $(this).dialog("close"); }  
                                    }); 
                              } });


@Html.ActionLink("Edit", "TaskTimeSheet", new {id="mylink", param = dr["id"].ToString() })

我必须通过此链接传递ID .....

这全部加载到表Table中每行都有Edit Button ....现在可以将ID传递给查询,..

From this link i have to pass id .....

This all is loaded in table Table Each row Have Edit Button ....now ho to pass Id to the querY,..

推荐答案

使用ajax调用

$('.btnSubmit').on('click', function(){
    $.ajax({
        url: '@Url.Action("Action", "Controller")',
        type: 'post',
        cache: false,
        async: true,
        data: { id: "ID" },
        success: function(result){
            $('.divContent').html(result);
        } 
    });
});

您的控制器动作类似于

[HttpPost]
public PartialViewResult Action(int id){
    var Model = //query the database
    return PartialView("_PartialView", Model);
}

这将调用您的控制器,返回局部视图,并将其放入具有"divContent"类的容器中.然后,您可以运行对话框代码以弹出容器.

This will call your controller, return a partial view and put it into a container with class "divContent". Then you can run your dialog code to pop up the container.

行ID更新

要获取表格行的ID,请在行点击事件中使用它

to get the id of a table row I use this in the row click event

$(this).closest('tr').find('.ID').val();  // or .html() if you have put it in the cell itself

这将获取您所在的行,然后在该行中找到具有类ID的单元格.希望这会有所帮助.

this will get the row that you are on and then find a cell in that row with class ID. Hopefully this helps.

这篇关于如何在jQUERY中传递ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆