c# - Pass values from Hidden field to ActionLink then to Controller -
i'm trying dynamically set studentids letting user select check boxes reports want. when click actionlink, use jquery set values of ids in hidden field. need action link read ids hidden field.
the values getting set in hidden field, not being passed controller actionlink.
i need pass reportids controller.
@html.actionlink("printmed", "getmededverificationreport", "student", new { studentidlist = model.reportids }, new { @class = "button print_selected print_selectedmeded disabled" }) @html.hiddenfor(model => model.reportids)
javascript
$('.print_selectedmeded').bind('click', function () { var ids = getprintids(); if (ids.length == 0) { return false; } $('#reportids').val(ids.tostring()); return true; });
when asp.net mvc render actionlink
generate link parameter have on model. event change value of model, not change value on output generated actionlink
.
given this, have se again value, try generate actionlink without argument:
@html.actionlink("printmed", "getmededverificationreport", "student", null, new { @class = "button print_selected print_selectedmeded disabled" })
on javascript side, try using on
method bind event handler , call preventdefault
method event argument, sample:
$('.print_selectedmeded').on('click', function (e) { e.preventdefault(); var ids = getprintids(); if (ids.length > 0) { $('#@html.idfor(model => model.reportids)').val(ids.tostring()); // make url redirect var url = $(this).prop("href") + "?studentidlist=" + ids.tostring(); // redirect using generated url window.location.href = url; } });
remember use html.idform()
make sure have right id specific property.
Comments
Post a Comment