繁体   English   中英

使用输入参数通过CSHTML页面调用void方法

[英]Call void method by CSHTML page with input parameter

我正在构建一个简单的MVC应用程序。 在我的CSHTML文件中,我将构建以下代码:

<script type="text/javascript">
        //modify as needed to make it pass in what you need.
    function GeneratePdf() {
        alert(idSlot);
            $.ajax({
                url: "@Url.Action("saveRROriginal", "Martinenko")",
                data: { idSlott:idSlot },
                cache: false,
                contentType: false,
                processData: false,
                type: "POST",
                success: function (data) {
                    //TODO: Add whatever if you want to pass a notification back
                    alert("success");
                },
                error: function (error) {
                    //TODO: Add some code here for error handling or notifications
                    alert("no success");
                }
            });
        }
</script>

<div class="col-md-12" style="width:100%;height:100%;margin-top:5px;">
            <button onclick=GeneratePdf()>
               Salva RR</button>
        </div>

这是void方法的代码:

public void saveRROriginal(String idSlott)
        {}

警报消息正确打印了idSlot的值,但在无效方法中idSlott = null。

您的json格式无效。 它应该是:

{ "idSlott": "idSlot" }

还向您的请求添加以下行:

contentType: "application/json; charset=utf-8",
dataType: "json",

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM