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.

1

1 Answer 1

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;
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.