javascript - How do I redirect to a action result in a mvc view -


when coding mvc 5 view, how redirect specific action result specifying controller, action result , parameter?

i wanting redirect action result in dashboard controller:

public actionresult location(long id) {  } 

i wanting in javascript function if possible.

here javascript code:

function mapmarkerclick(locationid) {     response.redirect(url.action("location", "dashboard", new { id == locationid })); } 

this error getting in browser console:

uncaught syntaxerror: unexpected token ==

solution 1 : use cshtml in javascript

    function mapmarkerclick(locationid)     {         var url = @url.action("location", "controller", new { id= locationid });         $.ajax({                 url: url ,                     success: function(){                     alert('success');                       }         });     } 

solution 2 : use actionlink render urls.

@html.actionlink("text", "location", "controller", new { id= locationid }) 

solution 3 : using ajax directly

$.post('controller', function(data) {    }); 

Comments