1

I have the following input button:

<input type="button" value="Log On" onclick="TryLogon(@Model)" style=" height:25px; width:75px"/>

And I want to pass the Model as a JSON param to the TryLogon function:

function TryLogon(model) {

    $.getJSON("/CertificateWebSite/Account/LogOnHelper", model, OnLogonResult);

}

How is it done correctly?

1 Answer 1

2

@Model won't be bound to anything that didn't exist on the initial page load.

Try changing how you're doing your log on click and what is being passed:

<input type="button" value="Log On" id="logOnButton" />

<script type="text/javascript">
    $(function(){
        $("#logOnButton").click(function(){
            var data = { username: $("#username").val(), password: $("#password").val() };
            $.getJSON("/CertificateWebSite/Account/LogOnHelper", data, OnLogonResult);
        });
    });
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

Also you can use jQuery's serialize method so you don't need to explicitly call out each input in the form.

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.