2

dropdown の変更に基づいて、テキストボックスに更新日時を設定する関数があります。

私のJquery:

function ModifymyDiv (element) {

    var option = $("#myDiv option:selected").text();
    var requrl = '@Url.Action("PopulateConfirmationFields", "Controller", null, Request.Url.Scheme, null)';
    $.ajax({
        type: "Get",
        url: requrl,

        success: function (data) {

            $('#txtconfTime').empty();
            $('#txtconfName').empty();
            $('#txtconfName').val(data.name);
            $('#txtconfTime').val(data.time);
        },
        error: function (failure) {
        }
    });
}

私のJsonメソッド:

 public ActionResult PopulateConfirmationFields()
        {
            User usr = userProxy.GetUserById(UserAppContext.UserOID);
            string name = string.Format("{1},{0}", usr.FirstName, usr.LastName);
            DateTime time = DateTime.Now;
            var t = new { name = name, time = time };
            return Json(t, JsonRequestBehavior.AllowGet);
        }

まだ私のテキストボックスに...

@Html.TextBoxFor(model => model.confirmationDateTime, new { id = "txtconfTime" })

DateTime 値は次のようになります ...

/Date(1348040819674)/

正しい Datetime Format を TextBox に渡すにはどうすればよいですか? PS文字列に変更することは、この特定のケースではオプションではありません。

4

2 に答える 2

1

解決策を見つけました:

        var jsonDate= data.time;
        var date = new Date(parseInt(jsonDate.substr(6)));
        var curr_date = date.getDate();
        var curr_month = date.getMonth();
        curr_month++; //January is represented by 0 
        var curr_year = date.getFullYear();
        var date =curr_month + "/" + curr_date + "/" + curr_year;
            $('#txtconfTime').empty();
            $('#txtconfName').empty();
            $('#txtconfName').val(data.name);
            $('#txtconfTime').val(date);
        },
于 2012-09-19T08:25:07.223 に答える
1

たとえば、次のことができます。

public ActionResult PopulateConfirmationFields()
        {
            User usr = userProxy.GetUserById(UserAppContext.UserOID);
            string name = string.Format("{1},{0}", usr.FirstName, usr.LastName);
            String time = DateTime.Now.ToString();
            var t = new { name = name, time = time };
            return Json(t, JsonRequestBehavior.AllowGet);
        }
于 2012-09-19T08:15:18.277 に答える