How can I set a default value in my editorboxes so that in case I don't write anything in the box it doesn't send a null value.
<div class="editor-label">
@Html.Label("Description")
</div> // somthing like
<div>@Html.EditorFor(model => model.Description, " Default value ")
@Html.ValidationMessageFor(model => model.Description)
</div>
Or if I change to:
@Html.TextBoxFor(Model.somthing, "Default value")
To display a default value in a field you must assign 'Value' property in htmlAttributes for it like in this example:
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control", @Value = ViewBag.DefaultDescription } })
Make sure that the V in Value is uppercase.
This way you will be just assigning a default value on the html field and not in the model.
Assigning default values in the model force you to create the model object first and that will set up default values for non-nullable fields like datetimes, that will make the page to show annoyings 1/1/1001 00:00:00 values in the datetime fields you could have in the rest of the model.