【问题标题】:Pass kendocalendar date to sql database将 kendocalendar 日期传递给 sql 数据库
【发布时间】:2013-09-02 09:05:54
【问题描述】:

场景: 我知道这是一个简单的日期时间转换,但我是后端和转换的新手。所以请帮助:我使用 mvc 和 ajax 将日期从 kendocalender 传递到调度程序以将其保存在数据库中: 这是我的代码: 控制器.cs

public int insertnote(string model,DateTime kendodate)
         {
             tblDailyNotes Dnote = new tblDailyNotes();
             int noteid = 0;
             //note.RealDate=Convert.ToString(
            Dnote.Note = model;
            Dnote.RealDate = kendodate;
            noteid = _scheduler.InsertDailynote(Dnote);
             return noteid;
         }

index.cshtml

  $("#dailynotes").change(function () {
            debugger;
            alert("Changed");
            var dailynotes = $('#dailynotes').val();

        var calendar = $("#SchedulerCalendar2").data("kendoCalendar");

        var cal = calendar.value(new Date());
        alert(cal);
        $.ajax({
           ![enter image description here][1]
            type: "POST",
            url: window.location.pathname + "Scheduler/insertnote",

            data: {model:dailynotes, kendodate: cal }
        })
         .success(function (result) {
             alert("note saved successfully");
         });
    });

问题:

这是呼叫警报

如何将此输出从 kendocalendar 转换为 "2013-09-01 13:27:14.480"(yyyy-mm-dd hh-mm-ss.sss) 这种格式使用 jquery 通过控制器功能将其保存在数据库中.请帮忙。

【问题讨论】:

    标签: c# asp.net-mvc-3 jquery


    【解决方案1】:

    您可以通过 DateTime.Parse 将字符串转换为 DateTime

    take a look at this

    【讨论】:

      【解决方案2】:

      我同意 user2675751 的解决方案。但是,我建议使用 Datetime.TryParse() 因为这不会引发异常并返回一个布尔值来指示成功或失败。这一点在 user2675751 提供的链接中有所介绍。通常最好不要信任来自客户端的数据。

      【讨论】:

        猜你喜欢
        • 2013-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-10
        • 2011-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多