如何通过 URL 传递日期?
这是我想要做的,因为您会看到日期使用了在 URL 中无效的正斜杠
http://localhost/Controller/Action/id=0d5375aa-6d43-42f1-91f0-ea73d9beb361&date=02/12/2009
最佳答案
您可以使用特定格式在查询字符串中传递日期,例如 yyyymmdd,然后在您的 Controller 中正确解析它。
&date=02/12/2009
change to
&date=20091202 (yyyymmdd)
您可以围绕使用这种新格式实例化的 DateTime 对象创建一个包装器,也可以自己在 Controller 中解析它。
public MyWrapperDate(int date)
{
int year = date / 10000;
int month = ((date - (10000 * year)) / 100);
int day = (date - (10000 * year) - (100 * month));
this.DateTimeObject = new DateTime(year, month, day);
}
关于asp.net-mvc - 如何通过 URL 传递日期,以便我的 Action 在 MVC 中读取?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1859181/