ajax在mvc中找不到方法 [英] ajax can't find method in mvc

查看:170
本文介绍了ajax在mvc中找不到方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

当我尝试将参数传递给mehod时我得到了

错误:找不到

我一直在尝试其他url语法(@ url.action)但也没有用。





输入/索引视图中的脚本

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>





prescaviController中的方法abrir



method abrir inside prescaviController

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

            Return View()
        End Function





也尝试了同一控制器的其他方法。

(Public Class prescaviController)有和没有参数 - 只是为了检查它是否触发了下一个动作




$ b带有../prescavi/abrir的$ b它给了我一个不同的错误,有或没有任何参数:SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符



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"

推荐答案

(document).ready(function(){
(document).ready(function () {


(#btnSubmit)。click(function(){
var presc1 =
("#btnSubmit").click(function () { var presc1 =


('#p1')。val();
('#p1').val();


这篇关于ajax在mvc中找不到方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆