How do I pass a datetime value as a URI parameter in asp.net mvc?

前端 未结 10 1110
孤城傲影
孤城傲影 2020-12-04 18:58

I need to have an action parameter that has a datetime value? Is there a standard way to do this? I need to have something like:

mysite/Controller/Action/2         


        
10条回答
  •  被撕碎了的回忆
    2020-12-04 19:43

    Since MVC 5 you can use the built in Attribute Routing package which supports a datetime type, which will accept anything that can be parsed to a DateTime.

    e.g.

    [GET("Orders/{orderDate:datetime}")]
    

    More info here.

提交回复
热议问题