Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery script needs value from asp.net mvc Razor ForEach
    primarykey
    data
    text
    <p>I have the following jQuery script to show a model dialog to enable editing of the selected item from a table:</p> <pre><code>&lt;script type="text/javascript"&gt; $(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'); }); }); </code></pre> <p></p> <p>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):</p> <pre><code>@foreach (var item in Model.Persons) { &lt;tr&gt; &lt;td&gt; @Html.DisplayFor(modelItem =&gt; item.Title.Name) &lt;/td&gt; ...... &lt;td&gt; &lt;button id="editperson"&gt;Edit&lt;/button&gt; &lt;/td&gt; &lt;/tr&gt; } </code></pre> <p>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 <strong>Need item.Id here</strong>).</p> <p>Is there a way to achieve this - or do I need to approach this in a different way?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload