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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -