jquery - MVC return a value from a jqueryui dialog modal -


i have simple dialog box opens on page ready, here code

this code on view

$(document).ready(         //dialog         $("#dialog").dialog({             title: "dialog box",             height: 300,             modal: true,             open: function(event, ui) {                 $(this).load("@url.action("testdialogview", "card")");             }         })     ); 

now opens dialog modal fine view contents of testdialogview. draw table in dialog (i can view), want try , is, when user clicks 1 of items in table, id of item posted view on, , id passed model.

example steps

  1. step 1: users loads cardtypes page
  2. step 2: dialog box shows list of items
  3. step 3: when clicking "view" link in table row
  4. step 4: id of item posted dialog
  5. step 5: dialog closes
  6. step 6: variable selectedid on cardtypes view model populated id posted dialog.

cheers

---update---

here screen shot of dialog,

enter image description here

and here view renders it

@model cardsite.models.filesearchmodel  @{     viewbag.title = "attacks"; }  <table class="table"> <tr>     <th>         @html.displaynamefor(x => x.name)     </th>     <th>         select     </th> </tr>  @foreach (var item in model.pokemonfiles) { <tr>     <td>             @html.displayfor(m => item.name)     </td>     <td>         <a href="">view</a>     </td> </tr> }  </table> 

what need change in view? should "view" link be?

you need have event delegation .on():

var selectedid = ''; $("#dialog").on('click', '.table a', function(){     selectedid = this.id; }); 

or if explain bit more step 4.


as per updated question don't see id in table or tr, td or anchor not having id.
here have changed answer little bit:

$("#dialog").on('click', '.table a', function(){     alert($(this).closest('tr').find('td:first').text()); }); 

the above code give first td's text in alert relative link clicked.


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -

PHPMotion implementation - URL based videos (Hosted on separate location) -