You can change the model property to return the default value if it is null (or sets default values ββwhen creating the model), or you can use the helper Html.TextBox
instead of Html.TextBoxFor
:
<%: Html.TextBox("FirstName", Model.FirstName ?? "The default value", new { id = "FirstName", placeholder = "[First Name]" }) %>
or use the value attribute:
<%: Html.TextBoxFor(model => model.FirstName, new { @Value = "The default value", id = "FirstName", placeholder = "[First Name]" }) %>
source share