将javascript日期发送到包含可为空的System.DateTime的.net对象

时间:2014-05-14 02:18:36

标签: javascript jquery .net ajax asp.net-mvc

我想将当前日期时间发送到.net对象,但无论我如何格式化日期,它都存在于ajax调用之前,但我的对象中的DateTime字段为空。

ajax可能看起来像这样

l_endDate = new Date();
$.ajax({
        url: 'api/customer/' + l_id,
        type: 'Put',
        data:
        {
            id: l_id,
            endDate: l_endDate
        }
    });

和我的c#看起来像这样:

[HttpPut]
[Route("")]
public HttpResponseMessage Put(int id, MyObject myObj)

除了其他属性之外,MyObject还有一个int id和一个Nullable System.DateTime endDate。当我单步执行时,我会看到我在对象中包含的ajax数据中填充的ID和其他字段,但endDate为null。

我看到很多堆栈溢出引用将.net DateTime转换为javascript,或者将json日期转换为DateTime,但我还没有找到与通过ajax发送的对象有关的内容。

有什么想法吗?

0 个答案:

没有答案