asp.net mvc - Pass argument to Javascript metod from Ajax ActionLink MVC3.0 -
i have problem sending parameter (id) javascript function. let me tell underlying idea: have training model , every training model has 1 survey. in below code generate pop-up link each training employee takes , display pop-up window. used ajax actionlink , in each part show popup window cretead div id of training. when oncomplete call javascript function openpopup show popup window not. in conclusion have different div's in popup window , want pass id of div javascript function. can tell me how solve problem?
thank you.
<script type="text/javascript"> $(document).ready(function (id) { $(id).dialog({ autoopen: false, title: 'anket', width: 500, height: 'auto', modal: true }); }); function openpopup(id) { $(id).dialog("open"); } </script> foreach (var training in model.traininglist) { <tr> <td class="view_detail_label"> eğitim adı </td> <td> @ajax.actionlink(training.name.name, "addsurvey", new { employeeid = model.id, trainingid = training.id }, new ajaxoptions { updatetargetid = training.id.tostring(), httpmethod = "get", insertionmode = insertionmode.replace, loadingelementid = "context", oncomplete = "openpopup('"+training.id.tostring()+"')" }) <div id="@training.id" style="display:none;"/> </td> </tr> } } </table>
you use plain html.actionlink unobtrusively ajaxify gives far more flexibility. seem have used id argument of document.ready function doesn't exist , has come from. document.ready callback doesn't take arguments.
so:
<script type="text/javascript"> $(document).ready(function () { $('.addsurvey').click(function() { $.ajax({ url: this.href, type: 'get', cache: false, context: this, success: function(result) { $(this).next('.result').html(result).dialog({ autoopen: true, title: 'anket', width: 500, height: 'auto', modal: true }); } }); return false; }); }); </script> <table> @foreach (var training in model.traininglist) { <tr> <td class="view_detail_label"> eğitim adı </td> <td> @html.actionlink( training.name.name, addsurvey, new { employeeid = model.id, trainingid = training.id }, new { @class = "addsurvey" } ) <div class="result"></div> </td> </tr> } </table> also recommend moving script out in separate javascript file , not mix markup scripts.
remark: since opening result of ajax call in modal dialog don't quite see point of having result div in each row. move out <table> , have single one.
Comments
Post a Comment