【问题标题】:unable to post the data with bool value in asp.net web api无法在 asp.net web api 中发布具有布尔值的数据
【发布时间】:2012-11-22 16:44:39
【问题描述】:

我正在使用现有数据库首先使用 EF 代码处理 asp.net mvc webapi。我有一门课,

public class User
{
public bool IsAgree{get; set;}
}

我用的是MySql数据库,我的表是这样的。

--------------
|ID  |IsAgree|
--------------
|int  |tinyint|
--------------

我有一个类似的帖子操作

public HttpReponseMessage PostUser(HttpRequestMessage request,User user)
{
// some code to handle user data..
}

在我看来,我正在尝试将一些数据发布到动作中,例如,

$(document).ready(function () {
            var sendata = {"IsAgree":true};
            $.ajax({
                url: '/api/account',
                type: 'POST',
                data: sendata,
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                cache: false,
                success: function (data) {
                    alert(data.status);
                },
                error: function (xhr) { alert(xhr.status); }
            });
        });

当我在操作中设置断点时,它显示用户为null,我收到警告消息为400,即错误请求。我的 json 数据是否适合我的模型?请指导我。

【问题讨论】:

    标签: asp.net-mvc jquery asp.net-web-api


    【解决方案1】:

    尝试以这种方式发送数据:

    数据:JSON.stringify({ sendata })

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2017-10-28
      • 2018-10-26
      • 1970-01-01
      • 2021-04-14
      • 2021-12-01
      • 1970-01-01
      相关资源
      最近更新 更多