default value of todays date

BitLost

Active member
Joined
Dec 10, 2016
Messages
35
Programming Experience
Beginner
I feel like I am looking for the wrong thing...and probably am.

I have some code in my app to allow the user to input the inspection date.

C#:
[COLOR=blue][FONT=Consolas]<[/FONT][/COLOR][COLOR=maroon][FONT=Consolas]div[/FONT][/COLOR][COLOR=black][FONT=Consolas] [/FONT][/COLOR][COLOR=red][FONT=Consolas]class[/FONT][/COLOR][COLOR=blue][FONT=Consolas]=[/FONT][/COLOR][COLOR=blue][FONT=Consolas]"form-group"[/FONT][/COLOR][COLOR=blue][FONT=Consolas]>[/FONT][/COLOR]               [COLOR=blue]<[/COLOR][COLOR=purple][B]label[/B][/COLOR] [COLOR=purple][B]asp-for[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"[/COLOR]InspectDate[COLOR=blue]"[/COLOR] [COLOR=red]class[/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"col-md-2 control-label"[/COLOR][COLOR=blue]></[/COLOR][COLOR=purple][B]label[/B][/COLOR][COLOR=blue]>[/COLOR]
               [COLOR=blue]<[/COLOR][COLOR=maroon]div[/COLOR] [COLOR=red]class[/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"col-md-10"[/COLOR][COLOR=blue]>[/COLOR]
                   [COLOR=blue]<[/COLOR][COLOR=purple][B]input[/B][/COLOR] [COLOR=purple][B]asp-for[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"[/COLOR]InspectDate[COLOR=blue]"[/COLOR] [COLOR=red]class[/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"form-control"[/COLOR] [COLOR=purple][B]value[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"[/COLOR]@[COLOR=#2b91af]DateTime[/COLOR].Today[COLOR=blue]"[/COLOR][COLOR=blue]/>[/COLOR]
                   [COLOR=blue]<[/COLOR][COLOR=purple][B]span[/B][/COLOR] [COLOR=purple][B]asp-validation-for[/B][/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"[/COLOR]InspectDate[COLOR=blue]"[/COLOR] [COLOR=red]class[/COLOR][COLOR=blue]=[/COLOR][COLOR=blue]"text-danger"[/COLOR] [COLOR=blue]/>[/COLOR]
               [COLOR=blue]</[/COLOR][COLOR=maroon]div[/COLOR][COLOR=blue]>[/COLOR] [COLOR=black][FONT=Consolas]           [/FONT][/COLOR][COLOR=blue][FONT=Consolas]</[/FONT][/COLOR][COLOR=maroon][FONT=Consolas]div[/FONT][/COLOR][COLOR=blue][FONT=Consolas]>[/FONT][/COLOR]

All I am wanting to do is insert a default value of todays date. It can be overwritten by the user if need as it is not critical. I keep thinking I should be able to do this in the view with some form of default for the input but...
 
The value for that field is coming from your model, like all the other fields. If you want that field to show today's date then set that property in the model, i.e. InspectDate, to today's date.
 
The value for that field is coming from your model, like all the other fields. If you want that field to show today's date then set that property in the model, i.e. InspectDate, to today's date.

Thanks...but wouldn't that also set a default in the database?

This is part of a larger issue I am looking at. I thought date would be easiest to start with so choose that.

This form has about 12 fields or so. 3 of these fields are common to all the data in this form at the time the user is taking the data. Therefore the intent was to add another button and have these fields retain value from last form to the next form. I thought this would be a controller action event. Am I confusing the two issues?
 
It's a controller action that displays the view and it's that action that provides the model for the view, therefore it's that action that sets the default value of that property before passing the model to the view.
 
It's a controller action that displays the view and it's that action that provides the model for the view, therefore it's that action that sets the default value of that property before passing the model to the view.

Thanks that makes much more sense to me. I wasn't looking at the controller that way.
 

Latest posts

Back
Top Bottom