I know that you can create a textbox using ASP.NET that will automatically be filled with whatever the value in the model is by using
<%: Html.TextBoxFor(model => model.FirstName, new { id = "FirstName", placeholder = "[First Name]" }) %>
Is there a way to give it a default value if model.FirstName is null?
I’ve tried adding a value attribute, but that didn’t work.
I also can’t pass in a model with that value included, because it will affect other areas of the form.
You could change the model property to return a default value if it’s null (or setting default values when creating the model) or you can use the
Html.TextBoxhelper instead ofHtml.TextBoxFor:or use the value-attribute: