asp.net mvc: default model binder problem

前端 未结 3 950
谎友^
谎友^ 2021-01-17 04:02

I\'ve got a MVC 3 view which displays a list of items that can be filtered by date.

The filter is a textbox which has been jQueryUI-fied into a date picker.

相关标签:
3条回答
  • 2021-01-17 04:44

    you can add a new route to routing table using

    routes.MapRoute(
    "SearchRoute", 
    "{controller}/{action}/{id}",
    new {controller = "Home", action = "Index", reportedDate = UrlParameter.Optional} 
    );
    

    then the your url will become

    MyController/Search/30-05-2011
    

    that will make your controller action catch the value of reportedDate

    but you have to chaneg the date format you used in your date picker

    0 讨论(0)
  • 2021-01-17 04:50

    Right, well the problem is the date format after all, it looks like the expected date format string is mm/dd/yyyy and the date is coming in as dd/mm/yyyy

    0 讨论(0)
  • 2021-01-17 04:52

    Veli is right. If you want to use that Date format, you'll need a custom model binder for your DateTime. Take a look here:

    How to specify date format for model binding?

    0 讨论(0)
提交回复
热议问题