2

I need to use @Url.Action to reach a MVC ASP.NET controller using the buton' click event and jQuery, so far this works for me

 $("#btnEneviar").click(function (e) {
            window.location.href = '@Url.Action(actionName: "TipoEvento", controllerName: "Home")';
        });

but now I need to send a parameter to the controller using the route, this is my code

 $("#btnEnviar").click(function (e)
        {    
            var valorAccion = $('#Table tr:eq(0) td:eq(1)').text();
            window.location.href = '@Url.Action("Solicitud", "Home", new { valor = valorAccion })';
        });

but I got the error: "the name valorAccion does not exits in the current context"

could you please help me to fix it.

Pablo Tobar
  • 614
  • 2
  • 13
  • 37
  • Possible duplicate of [Passing dynamic javascript values using Url.action()](https://stackoverflow.com/questions/15112055/passing-dynamic-javascript-values-using-url-action) – Doug F Mar 01 '19 at 22:06

1 Answers1

2

You're mixing server-side and client-side technologies so you can't really do it how you want to do it, but you can get around it by doing it like this:

    $("#btnEnviar").click(function (e) {
        var valorAccion = $('#Table tr:eq(0) td:eq(1)').text();
        window.location.href = '@Url.Action("Solicitud", "Home")?valor=' + valorAccion;
    });
Doug F
  • 894
  • 2
  • 13
  • 18