I want to Add Url.Action With Variable
<script type="text/javascript"> var a = Account; Var b = Index; window.location.href = '@Url.Action("a", "b")'; </script>
Hi ruben00000,
Use this script.
<script type="text/javascript"> window.location.href = '@Url.Action("Index", "Account")'; </script>
For more details refer
Show JavaScript alert after insert data and redirect to Index page using jQuery Ajax in ASP.Net MVC
In the @Url.Action() method you can not pass a client side value to it as a parameter.
So use like below.
<script type="text/javascript"> var a = 'Account'; var b = 'Index'; window.location.href = "/" + a + "/" + b + "/"; </script>
© COPYRIGHT 2025 ASPSnippets.com ALL RIGHTS RESERVED.