Asp.Net的mvc JQuery的AJAX的输入参数为null [英] Asp.Net Mvc JQuery ajax input parameters are null

查看:118
本文介绍了Asp.Net的mvc JQuery的AJAX的输入参数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试后使用jQuery的Ajax的一些数据,但在我的Ajax方法的参数为null。

I am trying to post some data with jQuery Ajax, but the parameters in my Ajax method are null.

这是简单的测试来发送数据:

This is simple test to send data:

 var dataPost = { titel: 'titel', message: 'msg', tagIds: 'hello' };
        jQuery.ajax({
            type: "POST",
            url: "Create",
            contentType: 'application/json; charset=utf-8',
            data: $.toJSON(dataPost),
            dataType: "json",
            success: function(result) {
                alert("Data Returned: ");
            }
        });

和我的Ajax方法是这样的:

And my Ajax method looks like this:

[HttpPost]
public ActionResult Create(string title, string message, string tagIds)
{... }

也有一些是基本的错误与我发送的数据,但我想不出什么。所有的时间标题,消息和tagIds为空,所以有一些错误的编码,我只是不知道是什么。

There is something basic wrong with the data I send, but I can't figure out what. All the time the title, message and tagIds are null, so there is something wrong with the encoding, I just don't know what.

最理想的参数tagIds应该是GUID的数组或列表。

Optimally the parameter tagIds should be an array or list of guids.

注:jQuery.toJSON这是插件

Note: The jQuery.toJSON is this plugin

推荐答案

创建控制器动作不期望的参数是JSON序列化,所以你不必。尝试将它们,而不是直接:

The Create controller action doesn't expect parameters to be JSON serialized so you don't have to. Try passing them directly instead:

var dataPost = { titel: 'titel', message: 'msg', tagIds: 'hello' };
jQuery.ajax({
    type: "POST",
    url: "Create",
    data: dataPost,
    dataType: "json",
    success: function(result) {
        alert("Data Returned: ");
    }
});

这篇关于Asp.Net的mvc JQuery的AJAX的输入参数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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