我正在使用一些日期参数对 Iframe url 进行编码:
var object = {
profileID: self.profileID(),
organisationID: self.organisationID(),
startDate: self.startDate(), // 09/04/2013
endDate: self.endDate() // 17/04/2013
};
iFrame.src = "ExportReportAllMediaDetailsCsv/?" + $.param(object);
编码后的网址:
http://dev.neptune.local/Report/ExportReportAllMediaDetailsCsv/?profileID=41&organisationID=2252&startDate=09%2F04%2F2013&endDate=17%2F04%2F2013
然而,有时调用的方法无法识别传入的日期时间:
The parameters dictionary contains a null entry for parameter 'endDate' of non-nullable type 'System.DateTime'
这是方法签名:
[CustomAuthorize(Definitions.RoleAnalystManager, Definitions.RoleProjectManager)]
public ActionResult ExportReportAllMediaDetailsCsv(int profileID, int organisationID, DateTime startDate, DateTime endDate)
最佳答案
您使用的是英国格式的日期字符串。因为只有 endDate
不工作,我的猜测是 startDate
被认为是 9 月 4 日。另一方面,因为没有一年中的第 17 个月,endDate
不能绑定(bind)到 DateTime
对象。
听起来您需要正确设置文化。尝试将以下内容添加到您的 Web.Config,在 <system.web>
下:
<globalization requestEncoding="utf-8" responseEncoding="utf-8"
culture="en-GB" />
有关全局化的更多信息,请参阅 http://msdn.microsoft.com/en-us/library/c6zyy3s9(v=vs.100).aspx
关于c# - asp.net mvc Controller 无法识别 DateTime url 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16273519/