gpt4 book ai didi

javascript - 无法在 mvc 获取 Controller 方法(来自 Uri())中从 QueryString 获取 DATETIME

转载 作者:行者123 更新时间:2023-11-30 17:51:59 35 4
gpt4 key购买 nike

 This is the query string that I am receiving in URL.

Output url: /demo/analysis/test?startDate=Sat+Jun+01+2013+00%3A00%3A00+GMT-0700+(Pacific+Daylight+Time)&endDate=Fri+Sep+13+2013+00%3A00%3A00+GMT-0700+(Pacific+Daylight+Time)

test controller:
Public Function GetData(<FromUri()> ByVal query As Request) As HttpResponseMessage
{
}

Request{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}

Angularjs API 代码:

   exportFunt = function () {
var query = generateExportData();
Export(query);
};


function generateExportData() {
return {
startDate: viewModel.StartDate,
endDate: viewModel.EndDate,
};
}

Export: function (query) {

$window.open('/demo/analysis/test?$.param(query), '_blank');
}

最佳答案

由于您不需要时间,我假设您从某种日期选择器中选择整个日历日期。只需将您的日期作为 yyyy-mm-dd 格式的字符串传递即可:

function pad(n) {
return n < 10 ? '0' + n : n;
}

function getDateString(dt) {
return [dt.getFullYear(),pad(dt.getMonth()+1),pad(dt.getDate())].join('-');
}

function generateExportData() {
return {
startDate: getDateString(viewModel.StartDate),
endDate: getDateString(viewModel.EndDate)
};
}

或者如果您不想自己编写所有这些,您可以考虑使用优秀的 moment.js图书馆:

function generateExportData() {
return {
startDate: moment(viewModel.StartDate).format('YYYY-MM-DD'),
endDate: moment(viewModel.EndDate).format('YYYY-MM-DD')
};
}

关于javascript - 无法在 mvc 获取 Controller 方法(来自 Uri())中从 QueryString 获取 DATETIME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18831620/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com