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
- step 1: users loads cardtypes page
- step 2: dialog box shows list of items
- step 3: when clicking "view" link in table row
- step 4: id of item posted dialog
- step 5: dialog closes
- step 6: variable selectedid on cardtypes view model populated id posted dialog.
cheers
---update---
here screen shot of dialog,
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
Post a Comment