Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7045759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:34:10+00:00 2026-05-28T02:34:10+00:00

I have the following jQuery script to show a model dialog to enable editing

  • 0

I have the following jQuery script to show a model dialog to enable editing of the selected item from a table:

<script type="text/javascript">
$(function () {
    $('#dialog').dialog({
        autoOpen: false,
        width: 800,
        resizable: false,
        title: 'Edit Person',
        modal: true,
        open: function (event, ui) {
            var url = '@Html.Raw(Url.Action("Edit", "Person", new {
                id = **Need item.Id here**,
                selectedPersonFor = Model.SelectedPersonFor,
                selectedPersonForId = Model.SelectedPersonForId,
                clientAccountId = Model.ClientAccountId
            }))';
            $(this).load(url);
        },
        buttons: {
            "Save": function () {
                $(this).dialog("save");
                // prevent the default action, e.g., following a link
                return false;
            },
            "Close": function () {
                $(this).dialog("close");
                // prevent the default action, e.g., following a link
                return false;
            }
        }
    });

    $('#editperson').click(function () {
        $('#dialog').dialog('open');
    });
});

This dialog is opened when the user clicks the edit button for a specific row in the following table (only partial mark up for table is shown):

@foreach (var item in Model.Persons)
{
   <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Title.Name)
        </td>
        ......
        <td>
            <button id="editperson">Edit</button>
        </td>
    </tr>
 }

What I need to be able to do is to get the item.id value from the foreach loop into my jQuery script to populate the id value in the url variable (I’ve marked the place in the script with the text Need item.Id here).

Is there a way to achieve this – or do I need to approach this in a different way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:34:10+00:00Added an answer on May 28, 2026 at 2:34 am

    One way to achieve this using the structure above is by adding a function to trigger the dialog manually and set the ‘working’ person ID before displaying it as follows:

    var workingPersonId;
    
    function showPersonDialog(personId) {
        workingPersonId = personId;
        $('#dialog').dialog('open');
    }
    
    $('#dialog').dialog({   
            autoOpen: false,   
            width: 800,   
            resizable: false,   
            title: 'Edit Person',   
            modal: true,   
            open: function (event, ui) {   
                var url = '@Html.Raw(Url.Action("Edit", "Person", new {   
                    id = workingPersonId,   
                    selectedPersonFor = Model.SelectedPersonFor,   
                    selectedPersonForId = Model.SelectedPersonForId,   
                    clientAccountId = Model.ClientAccountId   
                }))';   
                $(this).load(url);   
            },   
            buttons: {   
                "Save": function () {   
                    $(this).dialog("save");   
                    // prevent the default action, e.g., following a link   
                    return false;   
                },   
                "Close": function () {   
                    $(this).dialog("close");   
                    // prevent the default action, e.g., following a link   
                    return false;   
                }   
            }   
        });   
    

    Trigger with something like:

    <button id="editperson" onclick="showPersonDialog(@item.ID);return false;">Edit</button>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery <script type=text/javascript> jQuery(function(){ jQuery('.link1').click(function(){ jQuery('.hide-div').hide(); jQuery('.toggle1').show(); jQuery('#arrow').css({top: '0px'}); });
I have the following jquery function > <script type=text/javascript> > > $(document).ready(function() { >
I have the following code: <html> <head> <title>D</title> <script type=text/javascript src=jQuery.js> <script type=text/javascript> $(window).unload(
I have the following code: <html> <head> <script type=text/javascript language=javascript src=jquery/jquery-1.5.1.js></script> <script type=text/javascript language=javascript
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following jQuery script which hides/expands row in table: it was inspired
I have the following jQuery script on my site to switch tabs without reloading
I'm a jQuery novice, I have the following jQuery written to show a div
Folks, I have ASP.NET MVC 3 Application and I have the following JQuery script
So I now have the following jquery to hide or show a textbox based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.