Click here to Skip to main content
15,923,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
When trying to pass a parameter to the mehod I get
error: not found
I've been trying other url syntaxes (@url.action) but to no avail also.


script inside input/index view
<script>
    $(document).ready(function () {
          $("#btnSubmit").click(function () {
                var presc1 = $('#p1').val();
              
                $.ajax({
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json; charset=utf-8",
                    url: "prescavi/abrir",
                    data: "{presc1}",

                    success: function (data) {
                    alert("Success: " + success.d);
                    },
                    //call on ajax call failure
                    error: function (xhr, textStatus, error) {
                    alert("Error: " + error);
                    }
                });
            });
        });
<script>


method abrir inside prescaviController
<HttpPost>
        Function abrir(param As String) As ActionResult
            ViewData("Message") = "abriu! " & param & " ."

            Return View()
        End Function


also tried to other methods of the same controller.
( Public Class prescaviController ) with and without parameters - just to check if it triggered the next action


with "../prescavi/abrir" it gives me a different error, either with or without any parameters: "SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data"
Posted
Updated 3-Oct-15 1:04am
v2

1 solution

 
Share this answer
 
Comments
Nosfa 3-Oct-15 8:08am    
thanks.
it works. but the value passed is presc1, not the textbox value.

How to pass the varable data? Must I convert it to object?
Nosfa 3-Oct-15 8:21am    
solved it.

data: "{param:'" + presc1 + "'}",

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900