I have an html helper that I’d like to set a default on.
@Html.EditorFor(model => model.DateFrom)
What’s the syntax to set the default value of the helper if the model.DateFrom is null?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I dont think that using EditorFor you can set a default value. Consider setting it in the accessors on your model?
To do it on other types ( TextBoxFor etc ) You can set a value but not a default value. So you would need to do:
As I would reccomend:
Using things such as jquery date picker allow you to have a default value if the problem is that you are just posting nothing back if it has not been selected.