I have a simple web form where the data is stored in the DB. The problem I try to split the DateTime field into two controllers.
-One TextBoxFor for the Date YYYY/MM/DD
-One TextBoxFor for the Hours
-One TextBoxFor for the Minutes
The first controller succesfully saves the Date into the DB, no time (hours and minutes) but the two other controllers do not save anything into the DB.
Any help is appreciated.
<div class= "editor-field">
@Html.TextBoxFor(model => model.deliveryDate)
@Html.ValidationMessageFor(model => model.deliveryDate)
</div>
<div class="editor-label">
Tid
&l开发者_StackOverflowt;/div>
<div class= "editor-field">
@Html.TextBoxFor(model => model.deliveryDate.Hour)
@Html.TextBoxFor(model => model.deliveryDate.Minute)
</div>
Hour and minute of a DateTime i believe are read only. So when you try and set them it will fail.
one very easy way to get around this is to make presentation properties on the model which get displayed. eg model.Hour model.Minute
When these are set you can update the hour and minute of model.deliveryDate.
As a precaution I would also create a display property for deliveryDate as when you set this you will lose the time.
The overall best solution would be to get a good DateTime control. I think there is one in the box with MVC (not sure how good it is). Try one of these:
http://trentrichardson.com/examples/timepicker/
or for separate ones http://haineault.com/media/jquery/ui-timepickr/page/ and have a look at JqueryUI
精彩评论