Hi all.

I cannot pass the values from the textboxes onm a form to the controller.

view code

    <script type="text/javascript">
        $(document).ready(function () {
            $("#btnSubmit").click(function () {

                var presc1 = $('#p1').val(),
                    aviad1 = $('#a1').val(),


                $.ajax({
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",

                    url: "comparar",

                    data: "{'presc1':'" + presc1 + "', 'aviad1':'" + aviad1 + "'}",
 });
            });
        });
</script>


<div Class="container">

        @Html.BeginForm("comparar", "prescavi/comparar", FormMethod.Post)
        <div Class="col-md-12 col-xs-12">
            <div Class="col-md-6 col-xs-6">
                <div Class="col-md-4 col-xs-4">

                    <Label for="prescrito1"></Label>
                </div>

                <div Class="col-md-4 col-xs-4">
                    @Html.TextBox("p1")



                </div>
            </div>

            <div Class="col-md-6 col-xs-6">
                <div Class="col-md-4 col-xs-4">
                    <Label for="aviado1"></Label>
                </div>

                <div Class="col-md-4 col-xs-4">
                    @Html.TextBox("a1")
                </div>
            </div>
        </div>

<br><br>

        <div Class="col-md-12 col-xs-12">
            <div Class="col-md-6 col-xs-6">
                <div Class="col-md-4 col-xs-4">

                    <Label for="nada1a"></Label>
                </div>

                <div Class="col-md-4 col-xs-4">
                    <Label for="nada1b"></Label>
                </div>
            </div>

            <div Class="col-md-6 col-xs-6">
                <div Class="col-md-4 col-xs-4">
                    <Label for="nada2a"></Label>
                </div>

                <div Class="col-md-4 col-xs-4">
                    <input type="submit" name="btnSubmit" value="Send" />
                                       </div>
            </div>
        </div>
</div>

controller code

Public Function Comparar(ByVal presc1 As String, ByVal aviam1 As String)

            Return "you entered " & presc1 & " and " & aviam1 & ""

End Function

how to pass the data?
thanks in advance

Recommended Answers

All 2 Replies

data should be json and not a string, try:

data: { presc1: presc1, aviad1: aviad1 }

the problem is the script isn't fired up.

the form method/action and the button type were calling the method and not the script. therefore no data was passed.

already changed the button type to input and removed the method from the form.
this way the method is not called outside the script.

maybe it's not listening? Must I insert a listener?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.