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



我正在构建一个简单的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",

最新更新