0

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

Edited by nosfa

2
Contributors
2
Replies
19
Views
1 Year
Discussion Span
Last Post by nosfa
0

data should be json and not a string, try:

data: { presc1: presc1, aviad1: aviad1 }

Edited by pritaeas

0

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?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.