0

I would like to set default time to 12:00 AM on the input box, I have tried all sorts of stuff but its still displaying blank.

.cshtml

<div class="row">
    <div class="col-sm-6 mb-5">
        <div class="form-group">
            <label class="col-sm-3 col-form-label" label-for="Reminder">Time</label>
            <div class="col-sm-6">
                @Html.TextBoxFor(m => m.Reminder, new { @type = "time", @value = "12:00 AM", @class = "form-control", required = "", @placeholder = "12:00 AM" })
                @Html.ValidationMessageFor(m => m.Reminder, "", new { @class = "text-danger error-text" })
            </div>
        </div>
    </div>
</div>

Time Input field

4
  • value for input type time is 24 format so value should be 12:00 or 13:00 something like this without AM or PM .. you can take a look at developer.mozilla.org/en-US/docs/Web/HTML/Element/input/time Commented Dec 1, 2018 at 22:48
  • Maybe a duplicate for this one stackoverflow.com/questions/26418120/… Commented Dec 1, 2018 at 22:52
  • @Mohamed-Yousef if I use the <input type="time"> as per the example its working but I want to use Html.TextBoxFor since I want to bind value from the model if value exists. Commented Dec 1, 2018 at 23:06
  • @YashSoni I have set the property's value on the model, on the developer tools I can see the default value but on the text box its still blank. Commented Dec 1, 2018 at 23:07

1 Answer 1

2

This works for me:

@Html.TextBoxFor(model => model.time, new { @Type = "time", @Value = "22:15:00" })

Try:

type -> Type

value -> Value

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.