时间跨度一般在Asp.NET MVC 2的结合跨度、时间、Asp、NET

2023-09-03 02:05:54 作者:造梦怪咖丶o

我有一个绑定到一个模型中的输入表单。该模型具有时间跨度属性,但只有正确地获取价值,如果我输入时间为hh:mm或hh:mm:ss的。我想是因为它捕捉到的价值,即使它写成HHMM或hh.mm或HH.MM.SS还是......我想许多不同的格式进行正确分析。这可能吗?

I have an input form that is bound to a model. The model has a TimeSpan property, but it only gets the value correctly if I enter the time as hh:mm or hh:mm:ss. What I want is for it to capture the value even if it's written as hhmm or hh.mm or hh.mm.ss or ... I want many different formats to be parsed correctly. Is this possible?

谢谢!

推荐答案

是 - 编写自定义模型绑定您的模型对象。有一个关于这一点受到这里SO一个线程:http://stackoverflow.com/questions/2343913/asp-net-mvc2-custom-model-binder-examples

Yes - write a custom model binder for your model object. There's an thread about just that subject here on SO: http://stackoverflow.com/questions/2343913/asp-net-mvc2-custom-model-binder-examples