user3564166
user3564166

Reputation: 17

How To pass Id in jQUERY

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

here is my script

  $("#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() })

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,..

Upvotes: 1

Views: 2157

Answers (1)

Matt Bodily
Matt Bodily

Reputation: 6413

use an ajax call

$('.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);
        } 
    });
});

your controller action would be something like

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

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.

row id update

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

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

Upvotes: 1

Related Questions