简体   繁体   English

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

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

I'm building a simple MVC application. 我正在构建一个简单的MVC应用程序。 In my CSHTML file I'm build this code: 在我的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>

This is the code of void method: 这是void方法的代码:

public void saveRROriginal(String idSlott)
        {}

Alert message print correctly the value of idSlot but in void method idSlott = null. 警报消息正确打印了idSlot的值,但在无效方法中idSlott = null。

Your json format is not valid. 您的json格式无效。 It should be: 它应该是:

{ "idSlott": "idSlot" }

Also add following lines to your request: 还向您的请求添加以下行:

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

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

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