javascript - How to pass a value from underscore.js to the MVC Controller? -
using underscore.js in view, i'm trying pass variable serialnumberid view. here's tried:
<a href="@url.action("process", "wip", new { id = <%= serialnumberid %> })"> text </a> ...but didn't that. red squiggles.
then tried:
<a href="@url.action("process", "wip")/<%= serialnumberid %>"> text </a> ...but code never reached process action method in controller.
everything works fine if hardcode serialnumberid value this:
<a href="@url.action("process", "wip", new { id = 10 })"> text </a> or this:
<a href="@url.action("process", "wip")/10"> text </a> so how do that, serialnumberid variable instead?
edit: here's code serialnumberid coming (it's part of datatables function):
... columns: [ { data: 'serialnumberid', searchable: false, orderable: false, render: function (data, type, row, meta) { var structure = _.template($('#tmpl-actions').html()), html = structure({ serialnumberid: data }); return html; } }, edit 2: okay, after more playing around, don't think underscore problem. datatables problem. serialnumberid: data above null reason. when step through asp.net it's being filled int, time goes through datatables it's empty.
if serialnumberid jquery variable can't use razor syntax. if want create url can `
<script> $("a").click(function(){ var url='@url.action("process","wip")'+serialnumberid; window.location.href=url; }); </script>
Comments
Post a Comment