How to use a javascript variable in url.action with ASP.NET MVC WebForms view engine -
i want redirect user url in javascript function.
editclick: function () { var myid = 1; location.href = '<%= url.action("actionname", "controllername", new { id = myid})%>'; };
but 'myid' not exist in current context. how use js variable in url.action?
an approach i've taken in past generate link in view so:
<div class='clickmaster'> <div class='clicker' id='@url.action("actionname", "controllername", new { id = model.id })'> show here </div> <div class='clicker' id='@url.action("actionname", "controllername", new { id = model.id })'> show here </div> </div>
then in javascript defined function this:
$(function() { $('.clickmaster').on('click', '.clicker' , function() { location.href = this.id; }) });
Comments
Post a Comment