0

I am trying to call MVC action with parameters on html button click. I want to know how can i pass the textbox value as parameter to that action. Following is the code which i am using:

<input type="button" value="Create" onclick="location.href='@Url.Action("Verify", "Login", new { username = "'document.getElementById('txtUsername').value'", password="admin" } )'" />

i want to know the correct method / syntax of how to pass that textbox value

1
  • yes, but their they are passing hard coded parameter values, i want to know how can i pass the corresponding textbox value Commented Jul 25, 2018 at 20:03

1 Answer 1

0

You can do it in JavaScript.

Change your View to

<input type="button" value="Create" onclick="createUser()" />

In the JavaScript:

function createUser() {
    var username = document.getElementById('txtUsername').value;
    var password = "admin";
    $.ajax({
        // do the rest of work here
        type: "POST",
        data: {username: username, password: password },
        url: '@Url.Action("Verify", "Login")',
        async: true,
        success: function (data) {
            // do something
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.